Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 2ab7f92

Browse files
committed
Simplify path2uri
1 parent 65d2a81 commit 2ab7f92

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/util.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,13 @@ export function convertStringtoSymbolKind(kind: string): SymbolKind {
8484
* The returned URL uses protocol and host of the passed root URL
8585
*/
8686
export function path2uri(rootUri: URL, filePath: string): URL {
87-
const parts = filePath.split(/[\\\/]/);
88-
const isWindowsUri = parts[0].endsWith(':');
89-
// Don't encode colon after Windows drive letter
90-
if (isWindowsUri) {
91-
parts[0] = '/' + parts[0];
92-
} else {
93-
parts[0] = encodeURIComponent(parts[0]);
94-
}
95-
// Encode all other parts
96-
for (let i = 1; i < parts.length; i++) {
97-
parts[i] = encodeURIComponent(parts[i]);
87+
let pathname = filePath.replace(/\\/g, '/');
88+
if (/^\/[a-z]:\//i.test(pathname)) {
89+
pathname = '/' + pathname;
9890
}
99-
const pathname = parts.join(isWindowsUri ? '\\' : '/');
100-
return new URL(pathname, rootUri.href);
91+
const uri = new URL(rootUri.href);
92+
uri.pathname = pathname;
93+
return uri;
10194
}
10295

10396
/**

0 commit comments

Comments
 (0)