mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Include directories in completions for path mapping (#21103)
This commit is contained in:
@@ -94,7 +94,7 @@ namespace ts.Completions.PathCompletions {
|
||||
*
|
||||
* both foo.ts and foo.tsx become foo
|
||||
*/
|
||||
const foundFiles = createMap<boolean>();
|
||||
const foundFiles = createMap<true>();
|
||||
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<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>): string[] {
|
||||
function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>): string[] | undefined {
|
||||
return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 },
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user