diff --git a/src/services/completions.ts b/src/services/completions.ts index 2b47de8b7db..5b11fc7a3c1 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -208,6 +208,7 @@ import { isNamedImportsOrExports, isNamespaceImport, isNodeDescendantOf, + isNonContextualKeyword, isObjectBindingPattern, isObjectLiteralExpression, isObjectTypeDeclaration, @@ -1777,6 +1778,14 @@ function createCompletionEntry( hasAction = !importStatementCompletion; } + const parentNamedImportOrExport = findAncestor(location, isNamedImportsOrExports); + if (parentNamedImportOrExport?.kind === SyntaxKind.NamedImports) { + const possibleToken = stringToToken(name); + if (parentNamedImportOrExport && possibleToken && (possibleToken === SyntaxKind.AwaitKeyword || isNonContextualKeyword(possibleToken))) { + insertText = `${name} as ${name}_`; + } + } + // TODO(drosen): Right now we just permit *all* semantic meanings when calling // 'getSymbolKind' which is permissible given that it is backwards compatible; but // really we should consider passing the meaning for the node so that we don't report diff --git a/tests/cases/fourslash/completionInNamedImportLocation.ts b/tests/cases/fourslash/completionInNamedImportLocation.ts index 3ec4d07a701..af85aaba677 100644 --- a/tests/cases/fourslash/completionInNamedImportLocation.ts +++ b/tests/cases/fourslash/completionInNamedImportLocation.ts @@ -3,6 +3,7 @@ // @Filename: file.ts ////export var x = 10; ////export var y = 10; +////export { x as await, x as interface, x as unique }; ////export default class C { ////} @@ -10,12 +11,19 @@ // @Filename: a.ts ////import { /*1*/ } from "./file"; ////import { x, /*2*/ } from "./file"; +////import { x, y, /*3*/ } from "./file"; +////import { x, y, await as await_, /*4*/ } from "./file"; +////import { x, y, await as await_, interface as interface_, /*5*/ } from "./file"; +////import { x, y, await as await_, interface as interface_, unique, /*6*/ } from "./file"; goTo.file("a.ts"); verify.completions( { marker: "1", exact: [ + { name: "await", insertText: "await as await_" }, + { name: "interface", insertText: "interface as interface_" }, + { name: "unique" }, { name: "x", text: "var x: number" }, { name: "y", text: "var y: number" }, { name: "type", sortText: completion.SortText.GlobalsOrKeywords }, @@ -24,8 +32,39 @@ verify.completions( { marker: "2", exact: [ + { name: "await", insertText: "await as await_" }, + { name: "interface", insertText: "interface as interface_" }, + { name: "unique" }, { name: "y", text: "var y: number" }, { name: "type", sortText: completion.SortText.GlobalsOrKeywords }, ] }, + { + marker: "3", + exact: [ + { name: "await", insertText: "await as await_" }, + { name: "interface", insertText: "interface as interface_" }, + { name: "unique" }, + { name: "type", sortText: completion.SortText.GlobalsOrKeywords }, + ] + }, + { + marker: "4", + exact: [ + { name: "interface", insertText: "interface as interface_" }, + { name: "unique" }, + { name: "type", sortText: completion.SortText.GlobalsOrKeywords }, + ] + }, + { + marker: "5", + exact: [ + { name: "unique" }, + { name: "type", sortText: completion.SortText.GlobalsOrKeywords }, + ] + }, + { + marker: "6", + exact: [] + }, );