From 072e2f408bf5442a51b6ec4aa5c99d7fd7ec8dbd Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 21 Apr 2017 15:41:13 -0700 Subject: [PATCH] Pass Source and Level For TS/JS Errors (#25167) **Bug** All TS/JS diagnostics are currently reported as errors. We also cannot pass a custom source to identify them as coming from a tsserver plugin such as tslint **Fix** Add support for the new fields added in TS2.3.1 that provide this information --- extensions/typescript/src/protocol.const.ts | 7 ++++++ extensions/typescript/src/typescriptMain.ts | 25 ++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/extensions/typescript/src/protocol.const.ts b/extensions/typescript/src/protocol.const.ts index f7a0b0213a8..6990868683d 100644 --- a/extensions/typescript/src/protocol.const.ts +++ b/extensions/typescript/src/protocol.const.ts @@ -34,3 +34,10 @@ export class Kind { public static readonly variable = 'var'; public static readonly warning = 'warning'; } + + +export class DiagnosticCategory { + public static readonly error = 'error'; + + public static readonly warning = 'warning'; +} \ No newline at end of file diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index 5d0866dfcf5..4d8c74bbc54 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -9,7 +9,7 @@ * ------------------------------------------------------------------------------------------ */ 'use strict'; -import { env, languages, commands, workspace, window, ExtensionContext, Memento, IndentAction, Diagnostic, DiagnosticCollection, Range, Disposable, Uri, MessageItem, TextEditor, FileSystemWatcher } from 'vscode'; +import { env, languages, commands, workspace, window, ExtensionContext, Memento, IndentAction, Diagnostic, DiagnosticCollection, Range, Disposable, Uri, MessageItem, TextEditor, FileSystemWatcher, DiagnosticSeverity } from 'vscode'; // This must be the first statement otherwise modules might got loaded with // the wrong locale. @@ -20,6 +20,7 @@ const localize = nls.loadMessageBundle(); import * as path from 'path'; import * as Proto from './protocol'; +import * as PConst from './protocol.const'; import TypeScriptServiceClient from './typescriptServiceClient'; import { ITypescriptServiceClientHost } from './typescriptService'; @@ -628,13 +629,27 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost { private createMarkerDatas(diagnostics: Proto.Diagnostic[], source: string): Diagnostic[] { const result: Diagnostic[] = []; for (let diagnostic of diagnostics) { - let { start, end, text } = diagnostic; - let range = new Range(start.line - 1, start.offset - 1, end.line - 1, end.offset - 1); - let converted = new Diagnostic(range, text); - converted.source = source; + const { start, end, text } = diagnostic; + const range = new Range(start.line - 1, start.offset - 1, end.line - 1, end.offset - 1); + const converted = new Diagnostic(range, text); + converted.severity = this.getDiagnosticSeverity(diagnostic); + converted.source = diagnostic.source || source; converted.code = '' + diagnostic.code; result.push(converted); } return result; } + + private getDiagnosticSeverity(diagnostic: Proto.Diagnostic): DiagnosticSeverity { + switch (diagnostic.category) { + case PConst.DiagnosticCategory.error: + return DiagnosticSeverity.Error; + + case PConst.DiagnosticCategory.warning: + return DiagnosticSeverity.Warning; + + default: + return DiagnosticSeverity.Error; + } + } }