Skip to content

Commit a91b5e2

Browse files
committed
fix: ignore auto-imports
1 parent b70118f commit a91b5e2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/services/completions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ namespace ts.Completions {
10861086
const semanticStart = timestamp();
10871087
let completionKind = CompletionKind.None;
10881088
let isNewIdentifierLocation = false;
1089+
let isNonContextualObjectLiteral = false;
10891090
let keywordFilters = KeywordCompletionFilters.None;
10901091
// This also gets mutated in nested-functions after the return
10911092
let symbols: Symbol[] = [];
@@ -1471,6 +1472,8 @@ namespace ts.Completions {
14711472
}
14721473

14731474
function shouldOfferImportCompletions(): boolean {
1475+
// If current completion is for non-contextual Object literal shortahands, ignore auto-import symbols
1476+
if (isNonContextualObjectLiteral) return false;
14741477
// If not already a module, must have modules enabled.
14751478
if (!preferences.includeCompletionsForModuleExports) return false;
14761479
// If already using ES6 modules, OK to continue using them.
@@ -1898,6 +1901,7 @@ namespace ts.Completions {
18981901
if (objectLikeContainer.flags & NodeFlags.InWithStatement) {
18991902
return GlobalsSearch.Fail;
19001903
}
1904+
isNonContextualObjectLiteral = true;
19011905
return GlobalsSearch.Continue;
19021906
}
19031907
const completionsType = typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions);
@@ -1910,6 +1914,7 @@ namespace ts.Completions {
19101914
if (typeMembers.length === 0) {
19111915
// Edge case: If NumberIndexType exists
19121916
if (!hasNumberIndextype) {
1917+
isNonContextualObjectLiteral = true;
19131918
return GlobalsSearch.Continue;
19141919
}
19151920
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @module: esnext
2+
3+
// @Filename: /a.ts
4+
//// export const exportedConstant = 0;
5+
6+
// @Filename: /b.ts
7+
//// const obj = { exp/**/
8+
9+
verify.completions({
10+
marker: "",
11+
exact: completion.globalsPlus(['obj']),
12+
preferences: { includeCompletionsForModuleExports: true }
13+
});

0 commit comments

Comments
 (0)