diff --git a/src/tsWorker.ts b/src/tsWorker.ts index 3faf8f38..d9ea1431 100644 --- a/src/tsWorker.ts +++ b/src/tsWorker.ts @@ -121,21 +121,33 @@ 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; + 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); }