Keep fileName property of diagnostic objects and related information

This commit is contained in:
Sebastian Pahnke 2021-02-22 10:57:02 +01:00
parent e8b0174a8e
commit a1f9aeea18
3 changed files with 19 additions and 14 deletions

View file

@ -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<ts.Diagnostic[]>[] = [];
const promises: Promise<Diagnostic[]>[] = [];
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;

View file

@ -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;

View file

@ -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 = <ts.Diagnostic[]>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 <Diagnostic[]>diagnostics;
}