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

This commit is contained in:
Andy 2018-04-10 10:15:15 -07:00 committed by GitHub
parent 8248075550
commit 556a8010b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 20 deletions

View File

@ -4,6 +4,7 @@
interface DiagnosticDetails {
category: string;
code: number;
reportsUnnecessary?: {};
isEarly?: boolean;
}
@ -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}";

View File

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

View File

@ -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",
@ -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",
@ -3520,7 +3520,7 @@
"All imports in import declaration are unused.": {
"category": "Error",
"code": 6192,
"unused": true
"reportsUnnecessary": true
},
"Found 1 error.": {
"category": "Message",
@ -3609,7 +3609,7 @@
"Unused label.": {
"category": "Error",
"code": 7028,
"unused": true
"reportsUnnecessary": true
},
"Fallthrough case in switch.": {
"category": "Error",

View File

@ -4076,7 +4076,7 @@ namespace ts {
category: DiagnosticCategory;
code: number;
message: string;
unused?: {};
reportsUnnecessary?: {};
}
/**

View File

@ -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]);
@ -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);
@ -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 };
}
});

View File

@ -2172,6 +2172,8 @@ namespace ts.server.protocol {
*/
category: string;
reportsUnnecessary?: {};
/**
* The error code of the diagnostic message.
*/

View File

@ -80,6 +80,7 @@ namespace ts.server {
text: flattenDiagnosticMessageText(diag.messageText, "\n"),
code: diag.code,
category: diagnosticCategoryName(diag),
reportsUnnecessary: diag.reportsUnnecessary,
source: diag.source
};
}
@ -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 {

View File

@ -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.
@ -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.
*/

View File

@ -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.