From 8b18d160dbd3a0c6ab9bb73504bc2872a00d2dad Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Oct 2019 14:33:21 +0200 Subject: [PATCH] Provide related information to diagnostics --- src/languageFeatures.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 7dc0d1d..1ea0899 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -200,10 +200,31 @@ export class DiagnosticsAdapter extends Adapter { endLineNumber, endColumn, message: flattenDiagnosticMessageText(diag.messageText, '\n'), - code: diag.code.toString() + code: diag.code.toString(), + relatedInformation: this._convertRelatedInformation(resource, diag.relatedInformation) }; } + private _convertRelatedInformation(resource: Uri, relatedInformation?: ts.DiagnosticRelatedInformation[]): monaco.editor.IRelatedInformation[] { + if (relatedInformation === undefined) + return undefined; + + return relatedInformation.map(info => { + const relatedResource = info.file === undefined ? resource : monaco.Uri.parse(info.file.fileName); + const { lineNumber: startLineNumber, column: startColumn } = this._offsetToPosition(relatedResource, info.start); + const { lineNumber: endLineNumber, column: endColumn } = this._offsetToPosition(relatedResource, info.start + info.length); + + return { + resource: relatedResource, + startLineNumber, + startColumn, + endLineNumber, + endColumn, + message: flattenDiagnosticMessageText(info.messageText, '\n') + }; + }); + } + private _tsDiagnosticCategoryToMarkerSeverity(category: ts.DiagnosticCategory): monaco.MarkerSeverity { switch (category) { case ts.DiagnosticCategory.Error: return monaco.MarkerSeverity.Error