浏览代码

Merge pull request #21 from mattmccutchen/relatedInformation-cyclic

Clear the `file` fields of `relatedInformation` too. (WIP)
Alexandru Dima 7 年之前
父节点
当前提交
201fa54695
共有 1 个文件被更改,包括 15 次插入3 次删除
  1. 15 3
      src/tsWorker.ts

+ 15 - 3
src/tsWorker.ts

@@ -121,21 +121,33 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
 
 
 	// --- language features
 	// --- 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 = <ts.Diagnostic[]>diag.relatedInformation;
+			if (related) {
+				related.forEach(diag2 => diag2.file = undefined);
+			}
+		});
+	}
+
 	getSyntacticDiagnostics(fileName: string): Promise<ts.Diagnostic[]> {
 	getSyntacticDiagnostics(fileName: string): Promise<ts.Diagnostic[]> {
 		const diagnostics = this._languageService.getSyntacticDiagnostics(fileName);
 		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);
 		return Promise.as(diagnostics);
 	}
 	}
 
 
 	getSemanticDiagnostics(fileName: string): Promise<ts.Diagnostic[]> {
 	getSemanticDiagnostics(fileName: string): Promise<ts.Diagnostic[]> {
 		const diagnostics = this._languageService.getSemanticDiagnostics(fileName);
 		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);
 		return Promise.as(diagnostics);
 	}
 	}
 
 
 	getCompilerOptionsDiagnostics(fileName: string): Promise<ts.Diagnostic[]> {
 	getCompilerOptionsDiagnostics(fileName: string): Promise<ts.Diagnostic[]> {
 		const diagnostics = this._languageService.getCompilerOptionsDiagnostics();
 		const diagnostics = this._languageService.getCompilerOptionsDiagnostics();
-		diagnostics.forEach(diag => diag.file = undefined); // diag.file cannot be JSON'yfied
+		TypeScriptWorker.clearFiles(diagnostics);
 		return Promise.as(diagnostics);
 		return Promise.as(diagnostics);
 	}
 	}