From 116d3eda19ae7f2b38d261b69a780480441f662f Mon Sep 17 00:00:00 2001 From: Quoc Truong Date: Tue, 17 Mar 2020 13:19:12 -0700 Subject: [PATCH 1/2] Fix remote path bug --- src/debugAdapter/goDebug.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index c83a2a037..04fae51f0 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -305,9 +305,16 @@ function logError(...args: any[]) { logger.error(logArgsToString(args)); } +function findPathSeparator(filePath: string) { + return filePath.includes('/') ? '/' : '\\'; +} + function normalizePath(filePath: string) { if (process.platform === 'win32') { + const pathSeparator = findPathSeparator(filePath); filePath = path.normalize(filePath); + // Normalize will replace everything with backslash on Windows. + filePath = filePath.replace(/\\/g, pathSeparator); return fixDriveCasingInWindows(filePath); } return filePath; @@ -754,13 +761,6 @@ class GoDebugSession extends LoggingDebugSession { log('InitializeResponse'); } - protected findPathSeperator(filePath: string) { - if (/^(\w:[\\/]|\\\\)/.test(filePath)) { - return '\\'; - } - return filePath.includes('/') ? '/' : '\\'; - } - protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void { if (!args.program) { this.sendErrorResponse( @@ -835,10 +835,13 @@ class GoDebugSession extends LoggingDebugSession { if (this.delve.remotePath.length === 0) { return this.convertClientPathToDebugger(filePath); } + // When the filePath has a different path separator + // than the local path separator (cross-compilation), + // the split and join logic won't work. + // See github.com/microsoft/vscode-go/issues/2010. + filePath = filePath.replace(/\/|\\/g, this.remotePathSeparator); return filePath - .replace(this.delve.program, this.delve.remotePath) - .split(this.localPathSeparator) - .join(this.remotePathSeparator); + .replace(this.delve.program.replace(/\/|\\/g, this.remotePathSeparator), this.delve.remotePath); } protected toLocalPath(pathToConvert: string): string { @@ -1392,8 +1395,8 @@ class GoDebugSession extends LoggingDebugSession { } if (args.remotePath.length > 0) { - this.localPathSeparator = this.findPathSeperator(localPath); - this.remotePathSeparator = this.findPathSeperator(args.remotePath); + this.localPathSeparator = findPathSeparator(localPath); + this.remotePathSeparator = findPathSeparator(args.remotePath); const llist = localPath.split(/\/|\\/).reverse(); const rlist = args.remotePath.split(/\/|\\/).reverse(); From aae9fb4c1e6d5c44c13e2412795e1339a07d08f9 Mon Sep 17 00:00:00 2001 From: Quoc Truong Date: Thu, 19 Mar 2020 09:42:44 -0700 Subject: [PATCH 2/2] Update src/debugAdapter/goDebug.ts Co-Authored-By: Ramya Rao --- src/debugAdapter/goDebug.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 04fae51f0..35447a552 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -835,10 +835,9 @@ class GoDebugSession extends LoggingDebugSession { if (this.delve.remotePath.length === 0) { return this.convertClientPathToDebugger(filePath); } - // When the filePath has a different path separator - // than the local path separator (cross-compilation), - // the split and join logic won't work. - // See github.com/microsoft/vscode-go/issues/2010. + // The filePath may have a different path separator than the localPath + // So, update it to use the same separator as the remote path to ease + // in replacing the local path in it with remote path filePath = filePath.replace(/\/|\\/g, this.remotePathSeparator); return filePath .replace(this.delve.program.replace(/\/|\\/g, this.remotePathSeparator), this.delve.remotePath);