diff --git a/src/services/pathCompletions.ts b/src/services/pathCompletions.ts index 97569e0bae9..65d288e7f8d 100644 --- a/src/services/pathCompletions.ts +++ b/src/services/pathCompletions.ts @@ -94,7 +94,7 @@ namespace ts.Completions.PathCompletions { * * both foo.ts and foo.tsx become foo */ - const foundFiles = createMap(); + const foundFiles = createMap(); for (let filePath of files) { filePath = normalizePath(filePath); if (exclude && comparePaths(filePath, exclude, scriptPath, ignoreCase) === Comparison.EqualTo) { @@ -103,7 +103,7 @@ namespace ts.Completions.PathCompletions { const foundFileName = includeExtensions ? getBaseFileName(filePath) : removeFileExtension(getBaseFileName(filePath)); - if (!foundFiles.get(foundFileName)) { + if (!foundFiles.has(foundFileName)) { foundFiles.set(foundFileName, true); } } @@ -226,8 +226,9 @@ namespace ts.Completions.PathCompletions { const includeGlob = normalizedSuffix ? "**/*" : "./*"; const matches = tryReadDirectory(host, baseDirectory, fileExtensions, /*exclude*/ undefined, [includeGlob]); + const directories = tryGetDirectories(host, baseDirectory); // Trim away prefix and suffix - return mapDefined(matches, match => { + return mapDefined(concatenate(matches, directories), match => { const normalizedMatch = normalizePath(match); if (!endsWith(normalizedMatch, normalizedSuffix) || !startsWith(normalizedMatch, completePrefix)) { return; @@ -468,7 +469,7 @@ namespace ts.Completions.PathCompletions { return tryIOAndConsumeErrors(host, host.getDirectories, directoryName); } - function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray): string[] { + function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray, exclude?: ReadonlyArray, include?: ReadonlyArray): string[] | undefined { return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include); } diff --git a/tests/cases/fourslash/completionsPaths_pathMapping.ts b/tests/cases/fourslash/completionsPaths_pathMapping.ts index b2ec9ac6198..7a6283bce3a 100644 --- a/tests/cases/fourslash/completionsPaths_pathMapping.ts +++ b/tests/cases/fourslash/completionsPaths_pathMapping.ts @@ -3,6 +3,9 @@ // @Filename: /src/b.ts ////export const x = 0; +// @Filename: /src/dir/x.ts +/////export const x = 0; + // @Filename: /src/a.ts ////import {} from "foo/[|/**/|]"; @@ -17,4 +20,8 @@ ////} const [replacementSpan] = test.ranges(); -verify.completionsAt("", [{ name: "a", replacementSpan }, { name: "b", replacementSpan }]); +verify.completionsAt("", [ + { name: "a", replacementSpan }, + { name: "b", replacementSpan }, + { name: "dir", replacementSpan }, +]);