From 577cc1bd8af923766931594f1df087f215207fef Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 17 Jan 2023 19:41:16 +0200 Subject: [PATCH] fix(52233): Ambient modules declared with patterns are offered in path completions (#52246) --- src/services/stringCompletions.ts | 2 +- .../completionForStringLiteralImport3.baseline | 15 +++++++++++++++ .../completionForStringLiteralImport3.ts | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/completionForStringLiteralImport3.baseline create mode 100644 tests/cases/fourslash/completionForStringLiteralImport3.ts diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index 6ff21d4159b..42939f7fe13 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -1025,7 +1025,7 @@ function removeLeadingDirectorySeparator(path: string): string { function getAmbientModuleCompletions(fragment: string, fragmentDirectory: string | undefined, checker: TypeChecker): readonly string[] { // Get modules that the type checker picked up const ambientModules = checker.getAmbientModules().map(sym => stripQuotes(sym.name)); - const nonRelativeModuleNames = ambientModules.filter(moduleName => startsWith(moduleName, fragment)); + const nonRelativeModuleNames = ambientModules.filter(moduleName => startsWith(moduleName, fragment) && moduleName.indexOf("*") < 0); // Nested modules of the form "module-name/sub" need to be adjusted to only return the string // after the last '/' that appears in the fragment because that's where the replacement span diff --git a/tests/baselines/reference/completionForStringLiteralImport3.baseline b/tests/baselines/reference/completionForStringLiteralImport3.baseline new file mode 100644 index 00000000000..eb38cecad9e --- /dev/null +++ b/tests/baselines/reference/completionForStringLiteralImport3.baseline @@ -0,0 +1,15 @@ +[ + { + "marker": { + "fileName": "/a.ts", + "position": 22, + "name": "" + }, + "completionList": { + "isGlobalCompletion": false, + "isMemberCompletion": false, + "isNewIdentifierLocation": true, + "entries": [] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/completionForStringLiteralImport3.ts b/tests/cases/fourslash/completionForStringLiteralImport3.ts new file mode 100644 index 00000000000..8f3462915d3 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralImport3.ts @@ -0,0 +1,9 @@ +/// + +// @filename: /globals.d.ts +////declare module "*.css"; + +// @filename: /a.ts +////import * as foo from "/**/"; + +verify.baselineCompletions();