Skip to content

Commit

Permalink
Merge pull request #1662 from mattn/fix-windows-paths
Browse files Browse the repository at this point in the history
Fix Windows paths.
  • Loading branch information
octref authored Feb 28, 2020
2 parents 518d247 + 71f555c commit 05b4e7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions server/src/services/vls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { getFileFsPath } from '../utils/paths';

import {
DidChangeConfigurationParams,
Expand Down Expand Up @@ -198,7 +199,7 @@ export class VLS {

changes.forEach(c => {
if (c.type === FileChangeType.Changed) {
const fsPath = Uri.parse(c.uri).fsPath;
const fsPath = getFileFsPath(c.uri);
jsMode.onDocumentChanged!(fsPath);
}
});
Expand Down Expand Up @@ -349,8 +350,8 @@ export class VLS {
if (this.workspacePath && ref[0] === '/') {
return Uri.file(path.resolve(this.workspacePath, ref)).toString();
}
const docUri = Uri.parse(doc.uri);
return Uri.file(path.resolve(docUri.fsPath, '..', ref)).toString();
const fsPath = getFileFsPath(doc.uri);
return Uri.file(path.resolve(fsPath, '..', ref)).toString();
}
};

Expand Down
4 changes: 3 additions & 1 deletion server/src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export function getFilePath(documentUri: string): string {
const IS_WINDOWS = platform() === 'win32';
if (IS_WINDOWS) {
// Windows have a leading slash like /C:/Users/pine
return Uri.parse(documentUri).path.slice(1);
// vscode-uri use lower-case drive letter
// https://github.com/microsoft/vscode-uri/blob/95e03c06f87d38f25eda1ae3c343fe5b7eec3f52/src/index.ts#L1017
return Uri.parse(documentUri).path.replace(/^\/[a-zA-Z]/, (s: string) => s.slice(1).toLowerCase());
} else {
return Uri.parse(documentUri).path;
}
Expand Down

0 comments on commit 05b4e7a

Please sign in to comment.