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

Commit

Permalink
Address mismatch on path separators in debug config (#2010) (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
quoctruong committed Mar 19, 2020
1 parent 6d1bf5c commit 7da5077
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -835,10 +835,12 @@ class GoDebugSession extends LoggingDebugSession {
if (this.delve.remotePath.length === 0) {
return this.convertClientPathToDebugger(filePath);
}
// 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, 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 {
Expand Down Expand Up @@ -1392,8 +1394,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();
Expand Down

0 comments on commit 7da5077

Please sign in to comment.