Skip to content

Commit 8e0142d

Browse files
author
Andy
authored
Support import completions for a re-export with a different name from the original (#28055)
1 parent 778f438 commit 8e0142d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/services/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ namespace ts.Completions {
14101410
// If `symbol.parent !== ...`, this comes from an `export * from "foo"` re-export. Those don't create new symbols.
14111411
// If `some(...)`, this comes from an `export { foo } from "foo"` re-export, which creates a new symbol (thus isn't caught by the first check).
14121412
if (typeChecker.getMergedSymbol(symbol.parent!) !== resolvedModuleSymbol
1413-
|| some(symbol.declarations, d => isExportSpecifier(d) && !!d.parent.parent.moduleSpecifier)) {
1413+
|| some(symbol.declarations, d => isExportSpecifier(d) && !d.propertyName && !!d.parent.parent.moduleSpecifier)) {
14141414
continue;
14151415
}
14161416

tests/cases/fourslash/completionsImport_reExport_wrongName.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
/////**/
1313

1414
goTo.marker("");
15-
verify.completionListContains({ name: "x", source: "/a" }, "const x: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, {
16-
includeCompletionsForModuleExports: true,
17-
sourceDisplay: "./a",
15+
verify.completions({
16+
marker: "",
17+
includes: [
18+
{ name: "x", source: "/a", sourceDisplay: "./a", text: "const x: 0", hasAction: true },
19+
{ name: "y", source: "/index", sourceDisplay: ".", text: "(alias) const y: 0\nexport y", hasAction: true },
20+
],
21+
preferences: { includeCompletionsForModuleExports: true },
1822
});
1923

2024
verify.applyCodeActionFromCompletion("", {
@@ -25,3 +29,12 @@ verify.applyCodeActionFromCompletion("", {
2529
2630
`,
2731
});
32+
verify.applyCodeActionFromCompletion("", {
33+
name: "y",
34+
source: "/index",
35+
description: `Import 'y' from module "."`,
36+
newFileContent: `import { x } from "./a";
37+
import { y } from ".";
38+
39+
`,
40+
});

0 commit comments

Comments
 (0)