mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Merge pull request #76 from spahnke/related-diagnostic-fix
Deep clone diagnostic objects
This commit is contained in:
commit
e9fb83dcb1
1 changed files with 18 additions and 8 deletions
|
|
@ -8,6 +8,7 @@ import * as ts from './lib/typescriptServices';
|
||||||
import { libFileMap } from './lib/lib';
|
import { libFileMap } from './lib/lib';
|
||||||
import {
|
import {
|
||||||
Diagnostic,
|
Diagnostic,
|
||||||
|
DiagnosticRelatedInformation,
|
||||||
IExtraLibs,
|
IExtraLibs,
|
||||||
TypeScriptWorker as ITypeScriptWorker
|
TypeScriptWorker as ITypeScriptWorker
|
||||||
} from './monaco.contribution';
|
} from './monaco.contribution';
|
||||||
|
|
@ -177,17 +178,26 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
|
||||||
|
|
||||||
// --- language features
|
// --- language features
|
||||||
|
|
||||||
private static clearFiles(diagnostics: ts.Diagnostic[]): Diagnostic[] {
|
private static clearFiles(tsDiagnostics: ts.Diagnostic[]): Diagnostic[] {
|
||||||
// Clear the `file` field, which cannot be JSON'yfied because it
|
// Clear the `file` field, which cannot be JSON'yfied because it
|
||||||
// contains cyclic data structures, except for the `fileName`
|
// contains cyclic data structures, except for the `fileName`
|
||||||
// property.
|
// property.
|
||||||
diagnostics.forEach((diag: Diagnostic) => {
|
// Do a deep clone so we don't mutate the ts.Diagnostic object (see https://github.com/microsoft/monaco-editor/issues/2392)
|
||||||
diag.file = diag.file ? { fileName: diag.file.fileName } : undefined;
|
const diagnostics: Diagnostic[] = [];
|
||||||
diag.relatedInformation?.forEach(
|
for (const tsDiagnostic of tsDiagnostics) {
|
||||||
(diag2) => (diag2.file = diag2.file ? { fileName: diag2.file.fileName } : undefined)
|
const diagnostic: Diagnostic = { ...tsDiagnostic };
|
||||||
);
|
diagnostic.file = diagnostic.file ? { fileName: diagnostic.file.fileName } : undefined;
|
||||||
});
|
if (tsDiagnostic.relatedInformation) {
|
||||||
return <Diagnostic[]>diagnostics;
|
diagnostic.relatedInformation = [];
|
||||||
|
for (const tsRelatedDiagnostic of tsDiagnostic.relatedInformation) {
|
||||||
|
const relatedDiagnostic: DiagnosticRelatedInformation = { ...tsRelatedDiagnostic };
|
||||||
|
relatedDiagnostic.file = relatedDiagnostic.file ? { fileName: relatedDiagnostic.file.fileName } : undefined
|
||||||
|
diagnostic.relatedInformation.push(relatedDiagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diagnostics.push(diagnostic);
|
||||||
|
}
|
||||||
|
return diagnostics;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]> {
|
async getSyntacticDiagnostics(fileName: string): Promise<Diagnostic[]> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue