Skip to content

Add codes and categories to related information, officially #25304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
8 changes: 6 additions & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
};
}

Expand Down
6 changes: 4 additions & 2 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -13058,6 +13058,8 @@ declare namespace ts.server.protocol {
fileName: string;
}
interface DiagnosticRelatedInformation {
category: string;
code: number;
message: string;
span?: FileSpan;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down