From 634973d6b2e975b3aa514ae97a04036211ee63aa Mon Sep 17 00:00:00 2001 From: Fozi Date: Mon, 23 Jan 2017 20:24:12 -0500 Subject: [PATCH 1/3] Removing common parts from program and remotePath also returning '\' as a separator on Windows paths with mixes separators. --- src/debugAdapter/goDebug.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index cce40ce3a..c2375c95f 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -321,21 +321,35 @@ class GoDebugSession extends DebugSession { log('InitializeEvent'); } + protected findPathSeperator(path) { + if (/^(\w:[\\/]|\\\\)/.test(path)) return '\\'; + return path.includes('/') ? '/' : '\\'; + } + protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void { // 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(); + for(var i = 0; 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')); }; From df14353f6809d5f464870f1b229077c36f4e44e0 Mon Sep 17 00:00:00 2001 From: Fozi Date: Mon, 23 Jan 2017 20:48:35 -0500 Subject: [PATCH 2/3] replacing var with let --- src/debugAdapter/goDebug.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index c2375c95f..14e56011b 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -339,7 +339,8 @@ class GoDebugSession extends DebugSession { let llist = localPath.split(/\/|\\(?! )/).reverse(); let rlist = remotePath.split(/\/|\\(?! )/).reverse(); - for(var i = 0; i < llist.length; i++) if (llist[i] !== rlist[i]) break; + 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); From fe9550b027b0d6e78ea8b2adbb5036ca165f4930 Mon Sep 17 00:00:00 2001 From: Fozi Date: Mon, 23 Jan 2017 20:56:33 -0500 Subject: [PATCH 3/3] Found the whitespace and returned it to its spot. --- src/debugAdapter/goDebug.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 14e56011b..4f3220f81 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -340,7 +340,7 @@ class GoDebugSession extends DebugSession { let llist = localPath.split(/\/|\\(?! )/).reverse(); let rlist = remotePath.split(/\/|\\(?! )/).reverse(); let i = 0; - for(; i < llist.length; i++) if (llist[i] !== rlist[i]) break; + for (; i < llist.length; i++) if (llist[i] !== rlist[i]) break; if (i) { localPath = llist.reverse().slice(0, -i).join(this.localPathSeparator);