Suggestions now use diagnosticCollection (#32740)

Previously they used multiMaps, unlike all the other diagnostics. This
prevents duplicate suggestions, like other kinds diagnostics.

Fixes #28710
This commit is contained in:
Nathan Shively-Sanders 2019-08-06 11:15:06 -07:00 committed by GitHub
parent cc3db8f448
commit 269c3d3a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -585,7 +585,7 @@ namespace ts {
checkSourceFile(file);
Debug.assert(!!(getNodeLinks(file).flags & NodeCheckFlags.TypeChecked));
diagnostics = addRange(diagnostics, suggestionDiagnostics.get(file.fileName));
diagnostics = addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
if (!file.isDeclarationFile && (!unusedIsError(UnusedKind.Local) || !unusedIsError(UnusedKind.Parameter))) {
addUnusedDiagnostics();
}
@ -848,8 +848,7 @@ namespace ts {
const awaitedTypeStack: number[] = [];
const diagnostics = createDiagnosticCollection();
// Suggestion diagnostics must have a file. Keyed by source file name.
const suggestionDiagnostics = createMultiMap<DiagnosticWithLocation>();
const suggestionDiagnostics = createDiagnosticCollection();
const typeofTypesByName: ReadonlyMap<Type> = createMapFromTemplate<Type>({
string: stringType,
@ -944,7 +943,7 @@ namespace ts {
diagnostics.add(diagnostic);
}
else {
suggestionDiagnostics.add(diagnostic.file.fileName, { ...diagnostic, category: DiagnosticCategory.Suggestion });
suggestionDiagnostics.add({ ...diagnostic, category: DiagnosticCategory.Suggestion });
}
}
function errorOrSuggestion(isError: boolean, location: Node, message: DiagnosticMessage | DiagnosticMessageChain, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void {

View File

@ -0,0 +1,14 @@
// @strict: false
/// <reference path="fourslash.ts" />
// @Filename: foo.ts
//// import { f } from [|'m'|]
//// f
// @Filename: node_modules/m/index.js
//// module.exports.f = function (x) { return x }
verify.getSemanticDiagnostics([])
verify.getSuggestionDiagnostics([{
code: 7016,
message: "Could not find a declaration file for module 'm'. '/tests/cases/fourslash/node_modules/m/index.js' implicitly has an 'any' type.",
}])