Skip to content

Commit 269c3d3

Browse files
authored
Suggestions now use diagnosticCollection (#32740)
Previously they used multiMaps, unlike all the other diagnostics. This prevents duplicate suggestions, like other kinds diagnostics. Fixes #28710
1 parent cc3db8f commit 269c3d3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/compiler/checker.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ namespace ts {
585585
checkSourceFile(file);
586586
Debug.assert(!!(getNodeLinks(file).flags & NodeCheckFlags.TypeChecked));
587587

588-
diagnostics = addRange(diagnostics, suggestionDiagnostics.get(file.fileName));
588+
diagnostics = addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
589589
if (!file.isDeclarationFile && (!unusedIsError(UnusedKind.Local) || !unusedIsError(UnusedKind.Parameter))) {
590590
addUnusedDiagnostics();
591591
}
@@ -848,8 +848,7 @@ namespace ts {
848848
const awaitedTypeStack: number[] = [];
849849

850850
const diagnostics = createDiagnosticCollection();
851-
// Suggestion diagnostics must have a file. Keyed by source file name.
852-
const suggestionDiagnostics = createMultiMap<DiagnosticWithLocation>();
851+
const suggestionDiagnostics = createDiagnosticCollection();
853852

854853
const typeofTypesByName: ReadonlyMap<Type> = createMapFromTemplate<Type>({
855854
string: stringType,
@@ -944,7 +943,7 @@ namespace ts {
944943
diagnostics.add(diagnostic);
945944
}
946945
else {
947-
suggestionDiagnostics.add(diagnostic.file.fileName, { ...diagnostic, category: DiagnosticCategory.Suggestion });
946+
suggestionDiagnostics.add({ ...diagnostic, category: DiagnosticCategory.Suggestion });
948947
}
949948
}
950949
function errorOrSuggestion(isError: boolean, location: Node, message: DiagnosticMessage | DiagnosticMessageChain, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @strict: false
2+
/// <reference path="fourslash.ts" />
3+
// @Filename: foo.ts
4+
//// import { f } from [|'m'|]
5+
//// f
6+
7+
// @Filename: node_modules/m/index.js
8+
//// module.exports.f = function (x) { return x }
9+
10+
verify.getSemanticDiagnostics([])
11+
verify.getSuggestionDiagnostics([{
12+
code: 7016,
13+
message: "Could not find a declaration file for module 'm'. '/tests/cases/fourslash/node_modules/m/index.js' implicitly has an 'any' type.",
14+
}])

0 commit comments

Comments
 (0)