Skip to content

Commit bd1e975

Browse files
Jack-Worksiisaduan
andauthored
fix: import keyword name (#54675)
Co-authored-by: Isabel Duan <[email protected]>
1 parent 76869ee commit bd1e975

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/services/completions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ import {
208208
isNamedImportsOrExports,
209209
isNamespaceImport,
210210
isNodeDescendantOf,
211+
isNonContextualKeyword,
211212
isObjectBindingPattern,
212213
isObjectLiteralExpression,
213214
isObjectTypeDeclaration,
@@ -1777,6 +1778,14 @@ function createCompletionEntry(
17771778
hasAction = !importStatementCompletion;
17781779
}
17791780

1781+
const parentNamedImportOrExport = findAncestor(location, isNamedImportsOrExports);
1782+
if (parentNamedImportOrExport?.kind === SyntaxKind.NamedImports) {
1783+
const possibleToken = stringToToken(name);
1784+
if (parentNamedImportOrExport && possibleToken && (possibleToken === SyntaxKind.AwaitKeyword || isNonContextualKeyword(possibleToken))) {
1785+
insertText = `${name} as ${name}_`;
1786+
}
1787+
}
1788+
17801789
// TODO(drosen): Right now we just permit *all* semantic meanings when calling
17811790
// 'getSymbolKind' which is permissible given that it is backwards compatible; but
17821791
// really we should consider passing the meaning for the node so that we don't report

tests/cases/fourslash/completionInNamedImportLocation.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
// @Filename: file.ts
44
////export var x = 10;
55
////export var y = 10;
6+
////export { x as await, x as interface, x as unique };
67
////export default class C {
78
////}
89

910

1011
// @Filename: a.ts
1112
////import { /*1*/ } from "./file";
1213
////import { x, /*2*/ } from "./file";
14+
////import { x, y, /*3*/ } from "./file";
15+
////import { x, y, await as await_, /*4*/ } from "./file";
16+
////import { x, y, await as await_, interface as interface_, /*5*/ } from "./file";
17+
////import { x, y, await as await_, interface as interface_, unique, /*6*/ } from "./file";
1318

1419
goTo.file("a.ts");
1520
verify.completions(
1621
{
1722
marker: "1",
1823
exact: [
24+
{ name: "await", insertText: "await as await_" },
25+
{ name: "interface", insertText: "interface as interface_" },
26+
{ name: "unique" },
1927
{ name: "x", text: "var x: number" },
2028
{ name: "y", text: "var y: number" },
2129
{ name: "type", sortText: completion.SortText.GlobalsOrKeywords },
@@ -24,8 +32,39 @@ verify.completions(
2432
{
2533
marker: "2",
2634
exact: [
35+
{ name: "await", insertText: "await as await_" },
36+
{ name: "interface", insertText: "interface as interface_" },
37+
{ name: "unique" },
2738
{ name: "y", text: "var y: number" },
2839
{ name: "type", sortText: completion.SortText.GlobalsOrKeywords },
2940
]
3041
},
42+
{
43+
marker: "3",
44+
exact: [
45+
{ name: "await", insertText: "await as await_" },
46+
{ name: "interface", insertText: "interface as interface_" },
47+
{ name: "unique" },
48+
{ name: "type", sortText: completion.SortText.GlobalsOrKeywords },
49+
]
50+
},
51+
{
52+
marker: "4",
53+
exact: [
54+
{ name: "interface", insertText: "interface as interface_" },
55+
{ name: "unique" },
56+
{ name: "type", sortText: completion.SortText.GlobalsOrKeywords },
57+
]
58+
},
59+
{
60+
marker: "5",
61+
exact: [
62+
{ name: "unique" },
63+
{ name: "type", sortText: completion.SortText.GlobalsOrKeywords },
64+
]
65+
},
66+
{
67+
marker: "6",
68+
exact: []
69+
},
3170
);

0 commit comments

Comments
 (0)