mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Check auto-import completion for spread assignment (#56247)
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
@@ -3424,7 +3424,6 @@ function getCompletionData(
|
||||
|
||||
const semanticStart = timestamp();
|
||||
let completionKind = CompletionKind.None;
|
||||
let isNonContextualObjectLiteral = false;
|
||||
let hasUnresolvedAutoImports = false;
|
||||
// This also gets mutated in nested-functions after the return
|
||||
let symbols: Symbol[] = [];
|
||||
@@ -3894,8 +3893,6 @@ function getCompletionData(
|
||||
function shouldOfferImportCompletions(): boolean {
|
||||
// If already typing an import statement, provide completions for it.
|
||||
if (importStatementCompletion) return true;
|
||||
// If current completion is for non-contextual Object literal shortahands, ignore auto-import symbols
|
||||
if (isNonContextualObjectLiteral) return false;
|
||||
// If not already a module, must have modules enabled.
|
||||
if (!preferences.includeCompletionsForModuleExports) return false;
|
||||
// If already using ES modules, OK to continue using them.
|
||||
@@ -4340,7 +4337,6 @@ function getCompletionData(
|
||||
if (objectLikeContainer.flags & NodeFlags.InWithStatement) {
|
||||
return GlobalsSearch.Fail;
|
||||
}
|
||||
isNonContextualObjectLiteral = true;
|
||||
return GlobalsSearch.Continue;
|
||||
}
|
||||
const completionsType = typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions);
|
||||
@@ -4353,7 +4349,6 @@ function getCompletionData(
|
||||
if (typeMembers.length === 0) {
|
||||
// Edge case: If NumberIndexType exists
|
||||
if (!hasNumberIndextype) {
|
||||
isNonContextualObjectLiteral = true;
|
||||
return GlobalsSearch.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
70
tests/cases/fourslash/completionForObjectProperty.ts
Normal file
70
tests/cases/fourslash/completionForObjectProperty.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
//// export const foo = { bar: 'baz' };
|
||||
|
||||
// @Filename: /b.ts
|
||||
//// const test = foo/*1*/
|
||||
|
||||
// @Filename: /c.ts
|
||||
//// const test2 = {...foo/*2*/}
|
||||
|
||||
// @Filename: /d.ts
|
||||
//// const test3 = [{...foo/*3*/}]
|
||||
|
||||
// @Filename: /e.ts
|
||||
//// const test4 = { foo/*4*/ }
|
||||
|
||||
// @Filename: /f.ts
|
||||
//// const test5 = { foo: /*5*/ }
|
||||
|
||||
// @Filename: /g.ts
|
||||
//// const test6 = { unrelated: foo/*6*/ }
|
||||
|
||||
// @Filename: /i.ts
|
||||
//// const test7: { foo/*7*/: "unrelated" }
|
||||
|
||||
// @Filename: /h.ts
|
||||
//// const test8: { foo: string } = { foo/*8*/ }
|
||||
|
||||
verify.completions({
|
||||
marker: "1",
|
||||
includes: { name: "foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: true,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "2",
|
||||
includes: { name: "foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: false,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "3",
|
||||
includes: { name: "foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: false,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "4",
|
||||
includes: { name: "foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: true,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "5",
|
||||
includes: { name: "foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: false,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "6",
|
||||
includes: { name: "foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: false,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "7",
|
||||
excludes: "foo",
|
||||
isNewIdentifierLocation: true,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
}, {
|
||||
marker: "8",
|
||||
includes: { name: "foo", sortText: completion.SortText.LocationPriority },
|
||||
isNewIdentifierLocation: false,
|
||||
preferences: { includeCompletionsForModuleExports: true }
|
||||
});
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
exact: completion.globalsPlus(["foo"]),
|
||||
includes: { name: "exportedConstant", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions },
|
||||
isNewIdentifierLocation: true,
|
||||
preferences: { includeCompletionsForModuleExports: true },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user