Skip to content

Commit fed34cd

Browse files
author
Andy
authored
Fix bug: normalize path after combining (#21100)
1 parent 191b975 commit fed34cd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/services/pathCompletions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ namespace ts.Completions.PathCompletions {
216216
const expandedPrefixDirectory = fragmentHasPath ? combinePaths(normalizedPrefixDirectory, normalizedPrefixBase + getDirectoryPath(fragment)) : normalizedPrefixDirectory;
217217

218218
const normalizedSuffix = normalizePath(parsed.suffix);
219-
const baseDirectory = combinePaths(baseUrl, expandedPrefixDirectory);
219+
// Need to normalize after combining: If we combinePaths("a", "../b"), we want "b" and not "a/../b".
220+
const baseDirectory = normalizePath(combinePaths(baseUrl, expandedPrefixDirectory));
220221
const completePrefix = fragmentHasPath ? baseDirectory : ensureTrailingDirectorySeparator(baseDirectory) + normalizedPrefixBase;
221222

222223
// If we have a suffix, then we need to read the directory all the way down. We could create a glob
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /src/a.ts
4+
////import { } from "foo/[|/**/|]";
5+
6+
// @Filename: /oof/x.ts
7+
////export const x = 0;
8+
9+
// @Filename: /tsconfig.json
10+
////{
11+
//// "compilerOptions": {
12+
//// "baseUrl": "src",
13+
//// "paths": {
14+
//// "foo/*": ["../oof/*"]
15+
//// }
16+
//// }
17+
////}
18+
19+
const [replacementSpan] = test.ranges();
20+
verify.completionsAt("", [{ name: "x", replacementSpan }]);

0 commit comments

Comments
 (0)