Skip to content

Commit 7da5077

Browse files
authored
Address mismatch on path separators in debug config (#2010) (#3108)
1 parent 6d1bf5c commit 7da5077

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/debugAdapter/goDebug.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,16 @@ function logError(...args: any[]) {
305305
logger.error(logArgsToString(args));
306306
}
307307

308+
function findPathSeparator(filePath: string) {
309+
return filePath.includes('/') ? '/' : '\\';
310+
}
311+
308312
function normalizePath(filePath: string) {
309313
if (process.platform === 'win32') {
314+
const pathSeparator = findPathSeparator(filePath);
310315
filePath = path.normalize(filePath);
316+
// Normalize will replace everything with backslash on Windows.
317+
filePath = filePath.replace(/\\/g, pathSeparator);
311318
return fixDriveCasingInWindows(filePath);
312319
}
313320
return filePath;
@@ -754,13 +761,6 @@ class GoDebugSession extends LoggingDebugSession {
754761
log('InitializeResponse');
755762
}
756763

757-
protected findPathSeperator(filePath: string) {
758-
if (/^(\w:[\\/]|\\\\)/.test(filePath)) {
759-
return '\\';
760-
}
761-
return filePath.includes('/') ? '/' : '\\';
762-
}
763-
764764
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
765765
if (!args.program) {
766766
this.sendErrorResponse(
@@ -835,10 +835,12 @@ class GoDebugSession extends LoggingDebugSession {
835835
if (this.delve.remotePath.length === 0) {
836836
return this.convertClientPathToDebugger(filePath);
837837
}
838+
// The filePath may have a different path separator than the localPath
839+
// So, update it to use the same separator as the remote path to ease
840+
// in replacing the local path in it with remote path
841+
filePath = filePath.replace(/\/|\\/g, this.remotePathSeparator);
838842
return filePath
839-
.replace(this.delve.program, this.delve.remotePath)
840-
.split(this.localPathSeparator)
841-
.join(this.remotePathSeparator);
843+
.replace(this.delve.program.replace(/\/|\\/g, this.remotePathSeparator), this.delve.remotePath);
842844
}
843845

844846
protected toLocalPath(pathToConvert: string): string {
@@ -1392,8 +1394,8 @@ class GoDebugSession extends LoggingDebugSession {
13921394
}
13931395

13941396
if (args.remotePath.length > 0) {
1395-
this.localPathSeparator = this.findPathSeperator(localPath);
1396-
this.remotePathSeparator = this.findPathSeperator(args.remotePath);
1397+
this.localPathSeparator = findPathSeparator(localPath);
1398+
this.remotePathSeparator = findPathSeparator(args.remotePath);
13971399

13981400
const llist = localPath.split(/\/|\\/).reverse();
13991401
const rlist = args.remotePath.split(/\/|\\/).reverse();

0 commit comments

Comments
 (0)