diff --git a/src/services/pathCompletions.ts b/src/services/pathCompletions.ts index e9c8b48a7c4..97569e0bae9 100644 --- a/src/services/pathCompletions.ts +++ b/src/services/pathCompletions.ts @@ -216,7 +216,8 @@ namespace ts.Completions.PathCompletions { const expandedPrefixDirectory = fragmentHasPath ? combinePaths(normalizedPrefixDirectory, normalizedPrefixBase + getDirectoryPath(fragment)) : normalizedPrefixDirectory; const normalizedSuffix = normalizePath(parsed.suffix); - const baseDirectory = combinePaths(baseUrl, expandedPrefixDirectory); + // Need to normalize after combining: If we combinePaths("a", "../b"), we want "b" and not "a/../b". + const baseDirectory = normalizePath(combinePaths(baseUrl, expandedPrefixDirectory)); const completePrefix = fragmentHasPath ? baseDirectory : ensureTrailingDirectorySeparator(baseDirectory) + normalizedPrefixBase; // If we have a suffix, then we need to read the directory all the way down. We could create a glob diff --git a/tests/cases/fourslash/completionsPaths_pathMapping_parentDirectory.ts b/tests/cases/fourslash/completionsPaths_pathMapping_parentDirectory.ts new file mode 100644 index 00000000000..7dcd6e3adb1 --- /dev/null +++ b/tests/cases/fourslash/completionsPaths_pathMapping_parentDirectory.ts @@ -0,0 +1,20 @@ +/// + +// @Filename: /src/a.ts +////import { } from "foo/[|/**/|]"; + +// @Filename: /oof/x.ts +////export const x = 0; + +// @Filename: /tsconfig.json +////{ +//// "compilerOptions": { +//// "baseUrl": "src", +//// "paths": { +//// "foo/*": ["../oof/*"] +//// } +//// } +////} + +const [replacementSpan] = test.ranges(); +verify.completionsAt("", [{ name: "x", replacementSpan }]);