diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index cce40ce3a..4f3220f81 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -321,21 +321,36 @@ 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(); + 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')); };