From c3960730998f88f22f520af8b1502dc67e93896b Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 28 Jun 2018 13:29:06 -0700 Subject: [PATCH] Add codes and categories to related information, officially --- src/compiler/types.ts | 4 ++-- src/server/protocol.ts | 11 ++++++++--- src/server/session.ts | 8 ++++++-- tests/baselines/reference/api/tsserverlibrary.d.ts | 6 ++++-- tests/baselines/reference/api/typescript.d.ts | 4 ++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 64ee4a28f2c34..c2093693ba866 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4233,14 +4233,14 @@ namespace ts { } export interface Diagnostic extends DiagnosticRelatedInformation { - category: DiagnosticCategory; /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; - code: number; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } export interface DiagnosticRelatedInformation { + category: DiagnosticCategory; + code: number; file: SourceFile | undefined; start: number | undefined; length: number | undefined; diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 6d1c2dd717311..23894a0f67df0 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2254,11 +2254,16 @@ namespace ts.server.protocol { /** * Represents additional spans returned with a diagnostic which are relevant to it - * Like DiagnosticWithLinePosition, this is provided in two forms: - * - start and length of the span - * - startLocation and endLocation a pair of Location objects storing the start/end line offset of the span */ export interface DiagnosticRelatedInformation { + /** + * The category of the related information message, e.g. "error", "warning", or "suggestion". + */ + category: string; + /** + * The code used ot identify the related information + */ + code: number; /** * Text of related or additional information. */ diff --git a/src/server/session.ts b/src/server/session.ts index 2ad7c602d8647..972743d392195 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -84,7 +84,9 @@ namespace ts.server { function formatRelatedInformation(info: DiagnosticRelatedInformation): protocol.DiagnosticRelatedInformation { if (!info.file) { return { - message: flattenDiagnosticMessageText(info.messageText, "\n") + message: flattenDiagnosticMessageText(info.messageText, "\n"), + category: diagnosticCategoryName(info), + code: info.code }; } return { @@ -93,7 +95,9 @@ namespace ts.server { end: convertToLocation(getLineAndCharacterOfPosition(info.file, info.start! + info.length!)), // TODO: GH#18217 file: info.file.fileName }, - message: flattenDiagnosticMessageText(info.messageText, "\n") + message: flattenDiagnosticMessageText(info.messageText, "\n"), + category: diagnosticCategoryName(info), + code: info.code }; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 48ac4d9f979bb..cf281c13976f7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3595,14 +3595,14 @@ declare namespace ts { next?: DiagnosticMessageChain; } interface Diagnostic extends DiagnosticRelatedInformation { - category: DiagnosticCategory; /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; - code: number; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } interface DiagnosticRelatedInformation { + category: DiagnosticCategory; + code: number; file: SourceFile | undefined; start: number | undefined; length: number | undefined; @@ -13058,6 +13058,8 @@ declare namespace ts.server.protocol { fileName: string; } interface DiagnosticRelatedInformation { + category: string; + code: number; message: string; span?: FileSpan; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f5ace8e5b02f7..deb36f6ab757d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2397,14 +2397,14 @@ declare namespace ts { next?: DiagnosticMessageChain; } interface Diagnostic extends DiagnosticRelatedInformation { - category: DiagnosticCategory; /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ reportsUnnecessary?: {}; - code: number; source?: string; relatedInformation?: DiagnosticRelatedInformation[]; } interface DiagnosticRelatedInformation { + category: DiagnosticCategory; + code: number; file: SourceFile | undefined; start: number | undefined; length: number | undefined;