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

Commit

Permalink
Merge pull request #742 from f0zi/master
Browse files Browse the repository at this point in the history
Removing common parts from program and remotePath
  • Loading branch information
roblourens authored Feb 6, 2017
2 parents 40362d1 + fe9550b commit 958d4f8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ class GoDebugSession extends DebugSession {
verbose('InitializeResponse');
}

protected findPathSeperator(path) {
if (/^(\w:[\\/]|\\\\)/.test(path)) return '\\';
return path.includes('/') ? '/' : '\\';
}

protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
this.launchArgs = args;
const logLevel = args.trace === 'verbose' ?
Expand All @@ -353,19 +358,29 @@ class GoDebugSession extends DebugSession {
logger.setMinLogLevel(logLevel);

// Launch the Delve debugger on the program
let localPath = args.program;
let remotePath = args.remotePath || '';
let port = args.port || random(2000, 50000);
let host = args.host || '127.0.0.1';

if (remotePath.length > 0) {
this.localPathSeparator = args.program.includes('/') ? '/' : '\\';
this.remotePathSeparator = remotePath.includes('/') ? '/' : '\\';
if ((remotePath.endsWith('\\')) || (remotePath.endsWith('/'))) {
this.localPathSeparator = this.findPathSeperator(localPath);
this.remotePathSeparator = this.findPathSeperator(remotePath);

let llist = localPath.split(/\/|\\(?! )/).reverse();
let rlist = remotePath.split(/\/|\\(?! )/).reverse();
let i = 0;
for (; i < llist.length; i++) if (llist[i] !== rlist[i]) break;

if (i) {
localPath = llist.reverse().slice(0, -i).join(this.localPathSeparator);
remotePath = rlist.reverse().slice(0, -i).join(this.remotePathSeparator);
} else if ((remotePath.endsWith('\\')) || (remotePath.endsWith('/'))) {
remotePath = remotePath.substring(0, remotePath.length - 1);
}
}

this.delve = new Delve(args.mode, remotePath, port, host, args.program, args.args, args.showLog, args.cwd, args.env, args.buildFlags, args.init);
this.delve = new Delve(args.mode, remotePath, port, host, localPath, args.args, args.showLog, args.cwd, args.env, args.buildFlags, args.init);
this.delve.onstdout = (str: string) => {
this.sendEvent(new OutputEvent(str, 'stdout'));
};
Expand Down

0 comments on commit 958d4f8

Please sign in to comment.