Skip to content
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

Fix bug: ensure 'reportsUnnecessary' is actually sent by tsserver #23293

Merged
1 commit merged into from
Apr 10, 2018
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
10 changes: 6 additions & 4 deletions scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
interface DiagnosticDetails {
category: string;
code: number;
reportsUnnecessary?: {};
isEarly?: boolean;
}

Expand Down Expand Up @@ -59,14 +60,15 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFil
"/// <reference path=\"types.ts\" />\r\n" +
"/* @internal */\r\n" +
"namespace ts {\r\n" +
" function diag(code: number, category: DiagnosticCategory, key: string, message: string): DiagnosticMessage {\r\n" +
" return { code, category, key, message };\r\n" +
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}): DiagnosticMessage {\r\n" +
" return { code, category, key, message, reportsUnnecessary };\r\n" +
" }\r\n" +
" // tslint:disable-next-line variable-name\r\n" +
" export const Diagnostics = {\r\n";
messageTable.forEach(({ code, category }, name) => {
messageTable.forEach(({ code, category, reportsUnnecessary }, name) => {
const propName = convertPropertyName(name);
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}),\r\n`;
const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${reportsUnnecessary}` : "";
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}),\r\n`;
});

result += " };\r\n}";
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ namespace ts {
messageText: text,
category: message.category,
code: message.code,
reportsUnnecessary: message.unused,
reportsUnnecessary: message.reportsUnnecessary,
};
}

Expand Down Expand Up @@ -1637,7 +1637,7 @@ namespace ts {
messageText: text,
category: message.category,
code: message.code,
reportsUnnecessary: message.unused,
reportsUnnecessary: message.reportsUnnecessary,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@
"'{0}' is declared but its value is never read.": {
"category": "Error",
"code": 6133,
"unused": true
"reportsUnnecessary": true
},
"Report errors on unused locals.": {
"category": "Message",
Expand All @@ -3307,7 +3307,7 @@
"Property '{0}' is declared but its value is never read.": {
"category": "Error",
"code": 6138,
"unused": true
"reportsUnnecessary": true
},
"Import emit helpers from 'tslib'.": {
"category": "Message",
Expand Down Expand Up @@ -3520,7 +3520,7 @@
"All imports in import declaration are unused.": {
"category": "Error",
"code": 6192,
"unused": true
"reportsUnnecessary": true
},
"Found 1 error.": {
"category": "Message",
Expand Down Expand Up @@ -3609,7 +3609,7 @@
"Unused label.": {
"category": "Error",
"code": 7028,
"unused": true
"reportsUnnecessary": true
},
"Fallthrough case in switch.": {
"category": "Error",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4076,7 +4076,7 @@ namespace ts {
category: DiagnosticCategory;
code: number;
message: string;
unused?: {};
reportsUnnecessary?: {};
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4131,10 +4131,10 @@ namespace ts.projectSystem {
checkErrorMessage(session, "semanticDiag", { file: file1.path, diagnostics: [] });
});

it("info diagnostics", () => {
it("suggestion diagnostics", () => {
const file: FileOrFolder = {
path: "/a.js",
content: 'require("b")',
content: "function f(p) {}",
};

const host = createServerHost([file]);
Expand Down Expand Up @@ -4177,7 +4177,7 @@ namespace ts.projectSystem {
checkErrorMessage(session, "suggestionDiag", {
file: file.path,
diagnostics: [
createDiagnostic({ line: 1, offset: 1 }, { line: 1, offset: 13 }, Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module)
createDiagnostic({ line: 1, offset: 12 }, { line: 1, offset: 13 }, Diagnostics._0_is_declared_but_its_value_is_never_read, ["p"], "suggestion", /*reportsUnnecssary*/ true)
],
});
checkCompleteEvent(session, 2, expectedSequenceId);
Expand Down Expand Up @@ -4241,8 +4241,8 @@ namespace ts.projectSystem {
session.clearMessages();
});

function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: ReadonlyArray<string> = []): protocol.Diagnostic {
return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category: diagnosticCategoryName(message), source: undefined };
function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: ReadonlyArray<string> = [], category = diagnosticCategoryName(message), reportsUnnecessary?: {}): protocol.Diagnostic {
return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category, reportsUnnecessary, source: undefined };
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,8 @@ namespace ts.server.protocol {
*/
category: string;

reportsUnnecessary?: {};

/**
* The error code of the diagnostic message.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace ts.server {
text: flattenDiagnosticMessageText(diag.messageText, "\n"),
code: diag.code,
category: diagnosticCategoryName(diag),
reportsUnnecessary: diag.reportsUnnecessary,
source: diag.source
};
}
Expand All @@ -96,8 +97,8 @@ namespace ts.server {
const text = flattenDiagnosticMessageText(diag.messageText, "\n");
const { code, source } = diag;
const category = diagnosticCategoryName(diag);
return includeFileName ? { start, end, text, code, category, source, fileName: diag.file && diag.file.fileName } :
{ start, end, text, code, category, source };
return includeFileName ? { start, end, text, code, category, source, reportsUnnecessary: diag.reportsUnnecessary, fileName: diag.file && diag.file.fileName } :
{ start, end, text, code, category, reportsUnnecessary: diag.reportsUnnecessary, source };
}

export interface PendingErrorCheck {
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ declare namespace ts {
category: DiagnosticCategory;
code: number;
message: string;
unused?: {};
reportsUnnecessary?: {};
}
/**
* A linked list of formatted diagnostic messages to be used as part of a multiline message.
Expand Down Expand Up @@ -6758,6 +6758,7 @@ declare namespace ts.server.protocol {
* The category of the diagnostic message, e.g. "error", "warning", or "suggestion".
*/
category: string;
reportsUnnecessary?: {};
/**
* The error code of the diagnostic message.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ declare namespace ts {
category: DiagnosticCategory;
code: number;
message: string;
unused?: {};
reportsUnnecessary?: {};
}
/**
* A linked list of formatted diagnostic messages to be used as part of a multiline message.
Expand Down