From a1f9aeea189a95c0a0c605f6ceb9b3f4ba3d9cfc Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 22 Feb 2021 10:57:02 +0100 Subject: [PATCH] Keep fileName property of diagnostic objects and related information --- src/languageFeatures.ts | 12 ++++++++---- src/monaco.contribution.ts | 7 ++++--- src/tsWorker.ts | 14 +++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 00a99edf..749953ff 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -4,7 +4,11 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { LanguageServiceDefaults } from './monaco.contribution'; +import { + Diagnostic, + DiagnosticRelatedInformation, + LanguageServiceDefaults +} from './monaco.contribution'; import type * as ts from './lib/typescriptServices'; import type { TypeScriptWorker } from './tsWorker'; import { libFileSet } from './lib/lib.index'; @@ -244,7 +248,7 @@ export class DiagnosticsAdapter extends Adapter { return; } - const promises: Promise[] = []; + const promises: Promise[] = []; const { noSyntaxValidation, noSemanticValidation, @@ -297,7 +301,7 @@ export class DiagnosticsAdapter extends Adapter { ); } - private _convertDiagnostics(model: editor.ITextModel, diag: ts.Diagnostic): editor.IMarkerData { + private _convertDiagnostics(model: editor.ITextModel, diag: Diagnostic): editor.IMarkerData { const diagStart = diag.start || 0; const diagLength = diag.length || 1; const { lineNumber: startLineNumber, column: startColumn } = model.getPositionAt(diagStart); @@ -328,7 +332,7 @@ export class DiagnosticsAdapter extends Adapter { private _convertRelatedInformation( model: editor.ITextModel, - relatedInformation?: ts.DiagnosticRelatedInformation[] + relatedInformation?: DiagnosticRelatedInformation[] ): editor.IRelatedInformation[] | undefined { if (!relatedInformation) { return; diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 88da84da..534676f3 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -187,15 +187,16 @@ interface DiagnosticMessageChain { export interface Diagnostic extends DiagnosticRelatedInformation { /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; + reportsDeprecated?: {}; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } -interface DiagnosticRelatedInformation { +export interface DiagnosticRelatedInformation { /** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */ category: 0 | 1 | 2 | 3; code: number; - /** TypeScriptWorker removes this to avoid serializing circular JSON structures. */ - file: undefined; + /** TypeScriptWorker removes all but the `fileName` property to avoid serializing circular JSON structures. */ + file: { fileName: string } | undefined; start: number | undefined; length: number | undefined; messageText: string | DiagnosticMessageChain; diff --git a/src/tsWorker.ts b/src/tsWorker.ts index c43bd05f..be58d05f 100644 --- a/src/tsWorker.ts +++ b/src/tsWorker.ts @@ -179,13 +179,13 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork private static clearFiles(diagnostics: ts.Diagnostic[]): Diagnostic[] { // Clear the `file` field, which cannot be JSON'yfied because it - // contains cyclic data structures. - diagnostics.forEach((diag) => { - diag.file = undefined; - const related = diag.relatedInformation; - if (related) { - related.forEach((diag2) => (diag2.file = undefined)); - } + // contains cyclic data structures, except for the `fileName` + // property. + diagnostics.forEach((diag: Diagnostic) => { + diag.file = diag.file ? { fileName: diag.file.fileName } : undefined; + diag.relatedInformation?.forEach( + (diag2) => (diag2.file = diag2.file ? { fileName: diag2.file.fileName } : undefined) + ); }); return diagnostics; }