Skip to content

Commit 89d7cd5

Browse files
committed
Make sure that global module re-exports are short-cutted to be added to completions
1 parent c40ddb1 commit 89d7cd5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/services/completions.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,12 +1343,9 @@ namespace ts.Completions {
13431343
}
13441344

13451345
const symbolId = getSymbolId(symbol);
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-
}
1346+
symbols.push(symbol);
1347+
symbolToOriginInfoMap[symbolId] = origin;
1348+
symbolToSortTextMap[symbolId] = SortText.AutoImportSuggestions;
13521349
});
13531350
}
13541351
filterGlobalCompletion(symbols);
@@ -1468,7 +1465,7 @@ namespace ts.Completions {
14681465
}
14691466

14701467
/**
1471-
* Gathers symbols that can be imported from other files, deduplicating along the way. Symbols can be duplicates
1468+
* Gathers symbols that can be imported from other files, de-duplicating along the way. Symbols can be "duplicates"
14721469
* if re-exported from another module, e.g. `export { foo } from "./a"`. That syntax creates a fresh symbol, but
14731470
* it’s just an alias to the first, and both have the same name, so we generally want to filter those aliases out,
14741471
* if and only if the the first can be imported (it may be excluded due to package.json filtering in
@@ -1552,7 +1549,7 @@ namespace ts.Completions {
15521549
// Don't add another completion for `export =` of a symbol that's already global.
15531550
// So in `declare namespace foo {} declare module "foo" { export = foo; }`, there will just be the global completion for `foo`.
15541551
if (resolvedModuleSymbol !== moduleSymbol &&
1555-
every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator)) {
1552+
every(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator && !findAncestor(d, ts.isGlobalScopeAugmentation))) {
15561553
pushSymbol(resolvedModuleSymbol, moduleSymbol, /*skipFilter*/ true);
15571554
}
15581555

tests/cases/fourslash/completionsRedeclareModuleAsGlobal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path="fourslash.ts" />
22

3+
// 32675 - if this fails there are two copies of assert in completions
4+
35
// @esModuleInterop: true,
46
// @target: esnext
57

0 commit comments

Comments
 (0)