fix: import keyword name (#54675)

Co-authored-by: Isabel Duan <iduan@hmc.edu>
This commit is contained in:
Jack Works 2023-07-01 01:14:43 +08:00 committed by GitHub
parent 76869eeda1
commit bd1e9752d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -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

View File

@ -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: []
},
);