diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 320f4e9f4ddc1..0547fdb5d4bd1 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1624,6 +1624,7 @@ namespace ts { messageText: text, category: message.category, code: message.code, + unused: message.unused, }; } @@ -1653,7 +1654,8 @@ namespace ts { messageText: text, category: message.category, - code: message.code + code: message.code, + unused: message.unused, }; } @@ -1665,7 +1667,7 @@ namespace ts { code: chain.code, category: chain.category, - messageText: chain.next ? chain : chain.messageText + messageText: chain.next ? chain : chain.messageText, }; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9f95a66711b75..912814772a2c5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3250,7 +3250,8 @@ }, "'{0}' is declared but its value is never read.": { "category": "Error", - "code": 6133 + "code": 6133, + "unused": true }, "Report errors on unused locals.": { "category": "Message", @@ -3270,7 +3271,8 @@ }, "Property '{0}' is declared but its value is never read.": { "category": "Error", - "code": 6138 + "code": 6138, + "unused": true }, "Import emit helpers from 'tslib'.": { "category": "Message", @@ -3482,7 +3484,8 @@ }, "All imports in import declaration are unused.": { "category": "Error", - "code": 6192 + "code": 6192, + "unused": true }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", @@ -3562,7 +3565,8 @@ }, "Unused label.": { "category": "Error", - "code": 7028 + "code": 7028, + "unused": true }, "Fallthrough case in switch.": { "category": "Error", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 42d8462cecdb7..183ea4f07b682 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4009,6 +4009,7 @@ namespace ts { category: DiagnosticCategory; code: number; message: string; + unused?: {}; } /** @@ -4030,6 +4031,8 @@ namespace ts { length: number | undefined; messageText: string | DiagnosticMessageChain; category: DiagnosticCategory; + /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ + unused?: {}; code: number; source?: string; } diff --git a/src/server/client.ts b/src/server/client.ts index 578cbe507bc00..fc36ea316adbd 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -352,11 +352,11 @@ namespace ts.server { return this.getDiagnostics(file, CommandNames.SuggestionDiagnosticsSync); } - private getDiagnostics(file: string, command: CommandNames) { + private getDiagnostics(file: string, command: CommandNames): Diagnostic[] { const request = this.processRequest(command, { file, includeLinePosition: true }); const response = this.processResponse(request); - return (response.body).map(entry => { + return (response.body).map(entry => { const category = firstDefined(Object.keys(DiagnosticCategory), id => isString(id) && entry.category === id.toLowerCase() ? (DiagnosticCategory)[id] : undefined); return { @@ -365,7 +365,8 @@ namespace ts.server { length: entry.length, messageText: entry.message, category: Debug.assertDefined(category, "convertDiagnostic: category should not be undefined"), - code: entry.code + code: entry.code, + unused: entry.unused, }; }); } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 47c607966006b..667fd92fc6f60 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -455,6 +455,8 @@ namespace ts.server.protocol { endLocation: Location; category: string; code: number; + /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */ + unused?: {}; } /** diff --git a/src/services/shims.ts b/src/services/shims.ts index 1a43fbda14610..1e2fb7f0cc4db 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -588,6 +588,7 @@ namespace ts { length: number; category: string; code: number; + unused?: {}; } export function realizeDiagnostics(diagnostics: ReadonlyArray, newLine: string): RealizedDiagnostic[] { return diagnostics.map(d => realizeDiagnostic(d, newLine)); diff --git a/tests/cases/fourslash/codeFixUnusedIdentifier_suggestion.ts b/tests/cases/fourslash/codeFixUnusedIdentifier_suggestion.ts index 71de4fd190f50..de671de1e5db8 100644 --- a/tests/cases/fourslash/codeFixUnusedIdentifier_suggestion.ts +++ b/tests/cases/fourslash/codeFixUnusedIdentifier_suggestion.ts @@ -10,11 +10,13 @@ verify.getSuggestionDiagnostics([ message: "'p' is declared but its value is never read.", range: r0, code: 6133, + unused: true, }, { message: "'x' is declared but its value is never read.", range: r1, code: 6133, + unused: true, } ]); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index fd53a5acf2e8a..58339caa4ec35 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -527,6 +527,7 @@ declare namespace FourSlashInterface { /** @default `test.ranges()[0]` */ range?: Range; code: number; + unused?: true; } } declare function verifyOperationIsCancelled(f: any): void;