From deb94886fd5e64251c368620f8bf41f4603a5ed8 Mon Sep 17 00:00:00 2001 From: "wenlu.wang" <805037171@163.com> Date: Tue, 31 Oct 2017 16:10:38 -0500 Subject: [PATCH] fix completion module path (#19351)(#19367) (#19366) * completion module path with re-export(#19351) * completion module path with dynamic import(#19367) --- src/services/completions.ts | 6 ++- .../completionForStringLiteralExport.ts | 37 +++++++++++++++++++ ...letionForStringLiteralWithDynamicImport.ts | 33 +++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionForStringLiteralExport.ts create mode 100644 tests/cases/fourslash/completionForStringLiteralWithDynamicImport.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index f1e7fac2a4e..f4feb8a1c10 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -241,11 +241,15 @@ namespace ts.Completions { // a['/*completion position*/'] return getStringLiteralCompletionEntriesFromElementAccess(node.parent, typeChecker, compilerOptions.target, log); } - else if (node.parent.kind === SyntaxKind.ImportDeclaration || isExpressionOfExternalModuleImportEqualsDeclaration(node) || isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { + else if (node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration + || isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false) || isImportCall(node.parent) + || isExpressionOfExternalModuleImportEqualsDeclaration(node)) { // Get all known external module names or complete a path to a module // i.e. import * as ns from "/*completion position*/"; + // var y = import("/*completion position*/"); // import x = require("/*completion position*/"); // var y = require("/*completion position*/"); + // export * from "/*completion position*/"; return PathCompletions.getStringLiteralCompletionEntriesFromModuleNames(node, compilerOptions, host, typeChecker); } else if (isEqualityExpression(node.parent)) { diff --git a/tests/cases/fourslash/completionForStringLiteralExport.ts b/tests/cases/fourslash/completionForStringLiteralExport.ts new file mode 100644 index 00000000000..649148bb15d --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralExport.ts @@ -0,0 +1,37 @@ +/// + +// Should define spans for replacement that appear after the last directory seperator in export statements + +// @typeRoots: my_typings + +// @Filename: test.ts +//// export * from "./some/*0*/ +//// export * from "./sub/some/*1*/"; +//// export * from "some-/*2*/"; +//// export * from "..//*3*/"; +//// export {} from ".//*4*/"; + + +// @Filename: someFile1.ts +//// /*someFile1*/ + +// @Filename: sub/someFile2.ts +//// /*someFile2*/ + +// @Filename: my_typings/some-module/index.d.ts +//// export var x = 9; + +goTo.marker("0"); +verify.completionListContains("someFile1"); + +goTo.marker("1"); +verify.completionListContains("someFile2"); + +goTo.marker("2"); +verify.completionListContains("some-module"); + +goTo.marker("3"); +verify.completionListContains("fourslash"); + +goTo.marker("4"); +verify.completionListContains("someFile1"); diff --git a/tests/cases/fourslash/completionForStringLiteralWithDynamicImport.ts b/tests/cases/fourslash/completionForStringLiteralWithDynamicImport.ts new file mode 100644 index 00000000000..8e823991c0b --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralWithDynamicImport.ts @@ -0,0 +1,33 @@ +/// + +// Should define spans for replacement that appear after the last directory seperator in dynamic import statements + +// @typeRoots: my_typings + +// @Filename: test.ts +//// const a = import("./some/*0*/ +//// const a = import("./sub/some/*1*/"); +//// const a = import("some-/*2*/"); +//// const a = import("..//*3*/"); + + +// @Filename: someFile1.ts +//// /*someFile1*/ + +// @Filename: sub/someFile2.ts +//// /*someFile2*/ + +// @Filename: my_typings/some-module/index.d.ts +//// export var x = 9; + +goTo.marker("0"); +verify.completionListContains("someFile1"); + +goTo.marker("1"); +verify.completionListContains("someFile2"); + +goTo.marker("2"); +verify.completionListContains("some-module"); + +goTo.marker("3"); +verify.completionListContains("fourslash");