Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Develop (#1)
Browse files Browse the repository at this point in the history
* Use a more accurate way to guess the path OS

* Add missing semicolon

* Default remote workspace to local one

* Run prettier on changes
  • Loading branch information
hnioche authored May 9, 2019
1 parent 6568d75 commit 3fc67ca
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/debugger/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,29 +297,38 @@ class RubyDebugSession extends DebugSession {
return subPath && !subPath.startsWith('..') && !path.isAbsolute(subPath);
}

private getPathImplementation(absolutePath: string): any {
return path && path.posix.isAbsolute(absolutePath) ? path.posix : path.win32;
private getPathImplementation(pathToCheck: string): any {
if (pathToCheck) {
if (pathToCheck.indexOf(path.posix.sep) >= 0) {
return path.posix;
} else if (pathToCheck.indexOf(path.win32.sep) >= 0) {
return path.win32;
}
}

return path;
}

protected convertClientPathToDebugger(localPath: string): string {
if (this.debugMode === Mode.launch) {
return localPath;
}

let relativeLocalPath = path.relative(this.requestArguments.cwd, localPath)
let relativeLocalPath = path.relative(this.requestArguments.cwd, localPath);

if (!this.isSubPath(relativeLocalPath)) {
return localPath;
}

let remotePathImplementation = this.getPathImplementation(this.requestArguments.remoteWorkspaceRoot);
let remoteWorkspaceRoot =
this.requestArguments.remoteWorkspaceRoot || this.requestArguments.cwd;

let remotePathImplementation = this.getPathImplementation(remoteWorkspaceRoot);
let localPathImplementation = this.getPathImplementation(this.requestArguments.cwd);

let relativePath = remotePathImplementation.join.apply(
null,
[this.requestArguments.remoteWorkspaceRoot].concat(
relativeLocalPath.split(localPathImplementation.sep)
)
[remoteWorkspaceRoot].concat(relativeLocalPath.split(localPathImplementation.sep))
);

return relativePath;
Expand All @@ -330,20 +339,22 @@ class RubyDebugSession extends DebugSession {
return serverPath;
}

let remotePathImplementation = this.getPathImplementation(this.requestArguments.remoteWorkspaceRoot);
let remoteWorkspaceRoot =
this.requestArguments.remoteWorkspaceRoot || this.requestArguments.cwd;

let remotePathImplementation = this.getPathImplementation(remoteWorkspaceRoot);
let localPathImplementation = this.getPathImplementation(this.requestArguments.cwd);

let relativeRemotePath = remotePathImplementation.relative(this.requestArguments.remoteWorkspaceRoot, serverPath)
let relativeRemotePath = remotePathImplementation.relative(remoteWorkspaceRoot, serverPath);


if (!this.isSubPath(relativeRemotePath)) {
return serverPath;
}

let relativePath = localPathImplementation.join.apply(
null,
[this.requestArguments.cwd].concat(
relativeRemotePath.split(remotePathImplementation.sep)
)
[this.requestArguments.cwd].concat(relativeRemotePath.split(remotePathImplementation.sep))
);

return relativePath;
Expand Down

0 comments on commit 3fc67ca

Please sign in to comment.