Skip to content

Commit 53e163d

Browse files
authored
Add codes and categories to related information, officially (#25304)
1 parent c025cb2 commit 53e163d

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,14 +4233,14 @@ namespace ts {
42334233
}
42344234

42354235
export interface Diagnostic extends DiagnosticRelatedInformation {
4236-
category: DiagnosticCategory;
42374236
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
42384237
reportsUnnecessary?: {};
4239-
code: number;
42404238
source?: string;
42414239
relatedInformation?: DiagnosticRelatedInformation[];
42424240
}
42434241
export interface DiagnosticRelatedInformation {
4242+
category: DiagnosticCategory;
4243+
code: number;
42444244
file: SourceFile | undefined;
42454245
start: number | undefined;
42464246
length: number | undefined;

src/server/protocol.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,11 +2254,16 @@ namespace ts.server.protocol {
22542254

22552255
/**
22562256
* Represents additional spans returned with a diagnostic which are relevant to it
2257-
* Like DiagnosticWithLinePosition, this is provided in two forms:
2258-
* - start and length of the span
2259-
* - startLocation and endLocation a pair of Location objects storing the start/end line offset of the span
22602257
*/
22612258
export interface DiagnosticRelatedInformation {
2259+
/**
2260+
* The category of the related information message, e.g. "error", "warning", or "suggestion".
2261+
*/
2262+
category: string;
2263+
/**
2264+
* The code used ot identify the related information
2265+
*/
2266+
code: number;
22622267
/**
22632268
* Text of related or additional information.
22642269
*/

src/server/session.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ namespace ts.server {
8484
function formatRelatedInformation(info: DiagnosticRelatedInformation): protocol.DiagnosticRelatedInformation {
8585
if (!info.file) {
8686
return {
87-
message: flattenDiagnosticMessageText(info.messageText, "\n")
87+
message: flattenDiagnosticMessageText(info.messageText, "\n"),
88+
category: diagnosticCategoryName(info),
89+
code: info.code
8890
};
8991
}
9092
return {
@@ -93,7 +95,9 @@ namespace ts.server {
9395
end: convertToLocation(getLineAndCharacterOfPosition(info.file, info.start! + info.length!)), // TODO: GH#18217
9496
file: info.file.fileName
9597
},
96-
message: flattenDiagnosticMessageText(info.messageText, "\n")
98+
message: flattenDiagnosticMessageText(info.messageText, "\n"),
99+
category: diagnosticCategoryName(info),
100+
code: info.code
97101
};
98102
}
99103

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,14 +3595,14 @@ declare namespace ts {
35953595
next?: DiagnosticMessageChain;
35963596
}
35973597
interface Diagnostic extends DiagnosticRelatedInformation {
3598-
category: DiagnosticCategory;
35993598
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
36003599
reportsUnnecessary?: {};
3601-
code: number;
36023600
source?: string;
36033601
relatedInformation?: DiagnosticRelatedInformation[];
36043602
}
36053603
interface DiagnosticRelatedInformation {
3604+
category: DiagnosticCategory;
3605+
code: number;
36063606
file: SourceFile | undefined;
36073607
start: number | undefined;
36083608
length: number | undefined;
@@ -13058,6 +13058,8 @@ declare namespace ts.server.protocol {
1305813058
fileName: string;
1305913059
}
1306013060
interface DiagnosticRelatedInformation {
13061+
category: string;
13062+
code: number;
1306113063
message: string;
1306213064
span?: FileSpan;
1306313065
}

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,14 +2397,14 @@ declare namespace ts {
23972397
next?: DiagnosticMessageChain;
23982398
}
23992399
interface Diagnostic extends DiagnosticRelatedInformation {
2400-
category: DiagnosticCategory;
24012400
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
24022401
reportsUnnecessary?: {};
2403-
code: number;
24042402
source?: string;
24052403
relatedInformation?: DiagnosticRelatedInformation[];
24062404
}
24072405
interface DiagnosticRelatedInformation {
2406+
category: DiagnosticCategory;
2407+
code: number;
24082408
file: SourceFile | undefined;
24092409
start: number | undefined;
24102410
length: number | undefined;

0 commit comments

Comments
 (0)