Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize Windows paths to Unix style before comparing #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions tslint-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ function createProgram (updatedFileName: string, updatedContents: string, oldPro
const parsed = getParsedTsConfig();
const host = ts.createCompilerHost(parsed.options, true);
const realGetSourceFile = host.getSourceFile;
updatedFileName = fixSlashes(updatedFileName);
updatedFileName = toUnixPath(updatedFileName);

host.getSourceFile = function getSourceFile(fileName, languageVersion, onError) {
if (updatedFileName && updatedFileName.indexOf(fixSlashes(encodePath(fileName))) !== -1) {
if (updatedFileName && updatedFileName.indexOf(encodePath(toUnixPath(fileName))) !== -1) {
// Get contents from file currently being edited in editor.
return ts.createSourceFile(fileName, updatedContents, languageVersion, true);
} else {
Expand Down Expand Up @@ -593,17 +593,22 @@ function createProgram (updatedFileName: string, updatedContents: string, oldPro
}

/**
* Normalizes slashes (win32 vs. Posix).
* Encode path (and fix semicolon issue with Windows paths).
*/
function fixSlashes(path: string): string {
return path.replace(/\\/g, "/");
function encodePath(path: string): string {
return encodeURI(path).replace(/:/g, "%3A");
}

/**
* Encode path (and fix semicolon issue with Windows paths).
* Rewrite windows path to unix style path
*/
function encodePath(path: string): string {
return encodeURI(path).replace(/:/g, "%3A");
function toUnixPath(p: string): string {
p = p.replace(/\\/g, '/');
let double = /\/\//;
while(p.match(double)) {
p = p.replace(double, '');
}
return p;
}

/**
Expand Down