Skip to content

Commit c40ddb1

Browse files
committed
Does not add a duplicate completion when offering an export which was re-declared as a global - fixes #32675
1 parent b7c85c7 commit c40ddb1

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/services/completions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ namespace ts.Completions {
10001000
let completionKind = CompletionKind.None;
10011001
let isNewIdentifierLocation = false;
10021002
let keywordFilters = KeywordCompletionFilters.None;
1003+
// This also gets mutated in nested-functions after the return
10031004
let symbols: Symbol[] = [];
10041005
const symbolToOriginInfoMap: SymbolOriginInfoMap = [];
10051006
const symbolToSortTextMap: SymbolSortTextMap = [];
@@ -1342,9 +1343,12 @@ namespace ts.Completions {
13421343
}
13431344

13441345
const symbolId = getSymbolId(symbol);
1345-
symbols.push(symbol);
1346-
symbolToOriginInfoMap[symbolId] = origin;
1347-
symbolToSortTextMap[symbolId] = SortText.AutoImportSuggestions;
1346+
const existingSymbol = findLast(symbols, symbol => symbol.id === symbolId);
1347+
if (!existingSymbol) {
1348+
symbols.push(symbol);
1349+
symbolToOriginInfoMap[symbolId] = origin;
1350+
symbolToSortTextMap[symbolId] = SortText.AutoImportSuggestions;
1351+
}
13481352
});
13491353
}
13501354
filterGlobalCompletion(symbols);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @esModuleInterop: true,
4+
// @target: esnext
5+
6+
// @Filename: /myAssert.d.ts
7+
////declare function assert(value:any, message?:string):void;
8+
////export = assert;
9+
////export as namespace assert;
10+
11+
// @Filename: /ambient.d.ts
12+
////import assert from './myAssert';
13+
////
14+
////type Assert = typeof assert;
15+
////
16+
////declare global {
17+
//// const assert: Assert;
18+
////}
19+
20+
// @Filename: /index.ts
21+
/////// <reference path="./ambient.d.ts" />
22+
////asser/**/;
23+
24+
verify.completions({
25+
marker: "",
26+
includes: [
27+
{
28+
name: "assert",
29+
sortText: completion.SortText.GlobalsOrKeywords
30+
}
31+
],
32+
preferences: { includeCompletionsForModuleExports: true, includeInsertTextCompletions: true }
33+
});

0 commit comments

Comments
 (0)