mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
Merge pull request #74 from spahnke/related-filenames
Keep fileName property of diagnostic objects and related information
This commit is contained in:
commit
1dca22127c
3 changed files with 19 additions and 14 deletions
|
|
@ -4,7 +4,11 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
import {
|
||||||
|
Diagnostic,
|
||||||
|
DiagnosticRelatedInformation,
|
||||||
|
LanguageServiceDefaults
|
||||||
|
} from './monaco.contribution';
|
||||||
import type * as ts from './lib/typescriptServices';
|
import type * as ts from './lib/typescriptServices';
|
||||||
import type { TypeScriptWorker } from './tsWorker';
|
import type { TypeScriptWorker } from './tsWorker';
|
||||||
import { libFileSet } from './lib/lib.index';
|
import { libFileSet } from './lib/lib.index';
|
||||||
|
|
@ -244,7 +248,7 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises: Promise<ts.Diagnostic[]>[] = [];
|
const promises: Promise<Diagnostic[]>[] = [];
|
||||||
const {
|
const {
|
||||||
noSyntaxValidation,
|
noSyntaxValidation,
|
||||||
noSemanticValidation,
|
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 diagStart = diag.start || 0;
|
||||||
const diagLength = diag.length || 1;
|
const diagLength = diag.length || 1;
|
||||||
const { lineNumber: startLineNumber, column: startColumn } = model.getPositionAt(diagStart);
|
const { lineNumber: startLineNumber, column: startColumn } = model.getPositionAt(diagStart);
|
||||||
|
|
@ -328,7 +332,7 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
|
|
||||||
private _convertRelatedInformation(
|
private _convertRelatedInformation(
|
||||||
model: editor.ITextModel,
|
model: editor.ITextModel,
|
||||||
relatedInformation?: ts.DiagnosticRelatedInformation[]
|
relatedInformation?: DiagnosticRelatedInformation[]
|
||||||
): editor.IRelatedInformation[] | undefined {
|
): editor.IRelatedInformation[] | undefined {
|
||||||
if (!relatedInformation) {
|
if (!relatedInformation) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -187,15 +187,16 @@ interface DiagnosticMessageChain {
|
||||||
export interface Diagnostic extends DiagnosticRelatedInformation {
|
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. */
|
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
|
||||||
reportsUnnecessary?: {};
|
reportsUnnecessary?: {};
|
||||||
|
reportsDeprecated?: {};
|
||||||
source?: string;
|
source?: string;
|
||||||
relatedInformation?: DiagnosticRelatedInformation[];
|
relatedInformation?: DiagnosticRelatedInformation[];
|
||||||
}
|
}
|
||||||
interface DiagnosticRelatedInformation {
|
export interface DiagnosticRelatedInformation {
|
||||||
/** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */
|
/** Diagnostic category: warning = 0, error = 1, suggestion = 2, message = 3 */
|
||||||
category: 0 | 1 | 2 | 3;
|
category: 0 | 1 | 2 | 3;
|
||||||
code: number;
|
code: number;
|
||||||
/** TypeScriptWorker removes this to avoid serializing circular JSON structures. */
|
/** TypeScriptWorker removes all but the `fileName` property to avoid serializing circular JSON structures. */
|
||||||
file: undefined;
|
file: { fileName: string } | undefined;
|
||||||
start: number | undefined;
|
start: number | undefined;
|
||||||
length: number | undefined;
|
length: number | undefined;
|
||||||
messageText: string | DiagnosticMessageChain;
|
messageText: string | DiagnosticMessageChain;
|
||||||
|
|
|
||||||
|
|
@ -179,13 +179,13 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
|
||||||
|
|
||||||
private static clearFiles(diagnostics: ts.Diagnostic[]): Diagnostic[] {
|
private static clearFiles(diagnostics: 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.
|
// contains cyclic data structures, except for the `fileName`
|
||||||
diagnostics.forEach((diag) => {
|
// property.
|
||||||
diag.file = undefined;
|
diagnostics.forEach((diag: Diagnostic) => {
|
||||||
const related = <ts.Diagnostic[]>diag.relatedInformation;
|
diag.file = diag.file ? { fileName: diag.file.fileName } : undefined;
|
||||||
if (related) {
|
diag.relatedInformation?.forEach(
|
||||||
related.forEach((diag2) => (diag2.file = undefined));
|
(diag2) => (diag2.file = diag2.file ? { fileName: diag2.file.fileName } : undefined)
|
||||||
}
|
);
|
||||||
});
|
});
|
||||||
return <Diagnostic[]>diagnostics;
|
return <Diagnostic[]>diagnostics;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue