Skip to content

Commit c30ff7b

Browse files
andrius-praKeen Yee Liau
authored andcommitted
fix: use URI.file for converting file path to uri.
PR closes #396
1 parent e0f21ec commit c30ff7b

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

server/src/tests/utils_spec.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,41 @@ describe('filePathToUri', () => {
1414
expect(uri).toMatch(/^file/);
1515
});
1616

17-
it('should handle windows path', () => {
18-
const uri = filePathToUri('C:\\project\\main.ts');
19-
expect(uri).toBe('file:///c%3A%5Cproject%5Cmain.ts');
17+
it('should handle network path', () => {
18+
const uri = filePathToUri('//project/main.ts');
19+
expect(uri).toBe('file://project/main.ts');
2020
});
21+
22+
if (process.platform === 'win32') {
23+
it('should handle windows path', () => {
24+
const uri = filePathToUri('C:\\project\\main.ts');
25+
expect(uri).toBe('file:///c%3A/project/main.ts');
26+
});
27+
}
2128
});
2229

2330
describe('uriToFilePath', () => {
24-
it('should return valid fsPath for unix', () => {
25-
const filePath = uriToFilePath('file:///project/main.ts');
26-
expect(filePath).toBe('/project/main.ts');
27-
});
31+
if (process.platform === 'win32') {
32+
it('should return valid fsPath for windows', () => {
33+
const filePath = uriToFilePath('file:///c%3A/project/main.ts');
34+
expect(filePath).toBe('c:\\project\\main.ts');
35+
});
2836

29-
it('should return valid fsPath for windows', () => {
30-
const filePath = uriToFilePath('file:///c%3A%5Cproject%5Cmain.ts');
31-
expect(filePath).toBe('c:\\project\\main.ts');
32-
});
37+
it('should return valid fsPath for network file uri', () => {
38+
const filePath = uriToFilePath('file://project/main.ts');
39+
expect(filePath).toBe('\\\\project\\main.ts');
40+
});
41+
}
42+
43+
if (process.platform !== 'win32') {
44+
it('should return valid fsPath for unix', () => {
45+
const filePath = uriToFilePath('file:///project/main.ts');
46+
expect(filePath).toBe('/project/main.ts');
47+
});
48+
49+
it('should return valid fsPath for network file uri', () => {
50+
const filePath = uriToFilePath('file://project/main.ts');
51+
expect(filePath).toBe('//project/main.ts');
52+
});
53+
}
3354
});

server/src/utils.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ export function uriToFilePath(uri: string): string {
3434
* @param filePath
3535
*/
3636
export function filePathToUri(filePath: string): string {
37-
return URI
38-
.from({
39-
scheme: Scheme.File,
40-
path: filePath,
41-
})
42-
.toString();
37+
return URI.file(filePath).toString();
4338
}
4439

4540
/**

0 commit comments

Comments
 (0)