From 8e0142d709b2d324caaebd12908295448cff4d2c Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 22 Oct 2018 11:16:39 -0700 Subject: [PATCH] Support import completions for a re-export with a different name from the original (#28055) --- src/services/completions.ts | 2 +- .../completionsImport_reExport_wrongName.ts | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index e2c7be0298a..c5ef84836e4 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1410,7 +1410,7 @@ namespace ts.Completions { // If `symbol.parent !== ...`, this comes from an `export * from "foo"` re-export. Those don't create new symbols. // 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). if (typeChecker.getMergedSymbol(symbol.parent!) !== resolvedModuleSymbol - || some(symbol.declarations, d => isExportSpecifier(d) && !!d.parent.parent.moduleSpecifier)) { + || some(symbol.declarations, d => isExportSpecifier(d) && !d.propertyName && !!d.parent.parent.moduleSpecifier)) { continue; } diff --git a/tests/cases/fourslash/completionsImport_reExport_wrongName.ts b/tests/cases/fourslash/completionsImport_reExport_wrongName.ts index 1fe168b58a0..912f133e72a 100644 --- a/tests/cases/fourslash/completionsImport_reExport_wrongName.ts +++ b/tests/cases/fourslash/completionsImport_reExport_wrongName.ts @@ -12,9 +12,13 @@ /////**/ goTo.marker(""); -verify.completionListContains({ name: "x", source: "/a" }, "const x: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { - includeCompletionsForModuleExports: true, - sourceDisplay: "./a", +verify.completions({ + marker: "", + includes: [ + { name: "x", source: "/a", sourceDisplay: "./a", text: "const x: 0", hasAction: true }, + { name: "y", source: "/index", sourceDisplay: ".", text: "(alias) const y: 0\nexport y", hasAction: true }, + ], + preferences: { includeCompletionsForModuleExports: true }, }); verify.applyCodeActionFromCompletion("", { @@ -25,3 +29,12 @@ verify.applyCodeActionFromCompletion("", { `, }); +verify.applyCodeActionFromCompletion("", { + name: "y", + source: "/index", + description: `Import 'y' from module "."`, + newFileContent: `import { x } from "./a"; +import { y } from "."; + +`, +});