From 2d6f48ee53b68bcf7b45a148538308503e1a4ecc Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Tue, 31 Jul 2018 14:04:40 -0400 Subject: [PATCH 1/2] Clear the `file` fields of `relatedInformation` too. --- src/tsWorker.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/tsWorker.ts b/src/tsWorker.ts index 89cc3689..ca29bfcc 100644 --- a/src/tsWorker.ts +++ b/src/tsWorker.ts @@ -121,21 +121,34 @@ export class TypeScriptWorker implements ts.LanguageServiceHost { // --- language features + private static clearFiles(diagnostics: ts.Diagnostic[]) { + // Clear the `file` field, which cannot be JSON'yfied because it + // contains cyclic data structures. + diagnostics.forEach(diag => { + diag.file = undefined; + // FIXME: What is the procedure to upgrade the TypeScript typings? + const related = (diag).relatedInformation; + if (related) { + related.forEach(diag2 => diag2.file = undefined); + } + }); + } + getSyntacticDiagnostics(fileName: string): Promise { const diagnostics = this._languageService.getSyntacticDiagnostics(fileName); - diagnostics.forEach(diag => diag.file = undefined); // diag.file cannot be JSON'yfied + TypeScriptWorker.clearFiles(diagnostics); return Promise.as(diagnostics); } getSemanticDiagnostics(fileName: string): Promise { const diagnostics = this._languageService.getSemanticDiagnostics(fileName); - diagnostics.forEach(diag => diag.file = undefined); // diag.file cannot be JSON'yfied + TypeScriptWorker.clearFiles(diagnostics); return Promise.as(diagnostics); } getCompilerOptionsDiagnostics(fileName: string): Promise { const diagnostics = this._languageService.getCompilerOptionsDiagnostics(); - diagnostics.forEach(diag => diag.file = undefined); // diag.file cannot be JSON'yfied + TypeScriptWorker.clearFiles(diagnostics); return Promise.as(diagnostics); } From a56039de2d62e5f21ba325325f703b3a966c4044 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 8 Aug 2018 15:46:01 +0200 Subject: [PATCH 2/2] Remove any cast --- src/tsWorker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tsWorker.ts b/src/tsWorker.ts index 8094bdba..d9ea1431 100644 --- a/src/tsWorker.ts +++ b/src/tsWorker.ts @@ -126,8 +126,7 @@ export class TypeScriptWorker implements ts.LanguageServiceHost { // contains cyclic data structures. diagnostics.forEach(diag => { diag.file = undefined; - // FIXME: What is the procedure to upgrade the TypeScript typings? - const related = (diag).relatedInformation; + const related = diag.relatedInformation; if (related) { related.forEach(diag2 => diag2.file = undefined); }