This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 645
Fix remote path bug (#2010) #3108
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
quoctruong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filePath = filePath.replace(/\/|\\/g, this.remotePathSeparator); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wonder if it's doable to write some unit tests to check these path manipulation functions. |
||
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(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility that the path has both / and ? The new change selects / in that case while the old findPathSeparator picks \ if it matches the above pattern (in line 758). Wonder if that would be potentially a problem.