-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix clicking on context files with absolute paths on Windows #2400
Conversation
Fixes #2399 by removing a duplicate call to open a file which expected a file URI but was given a path, and only tries to join a path with the workspace URI if it's a relative path.
@@ -22,14 +24,18 @@ export async function openFilePath( | |||
currentViewColumn?: vscode.ViewColumn, | |||
range?: ActiveTextEditorSelectionRange | |||
): Promise<void> { | |||
void vscode.commands.executeCommand('vscode.open', filePath) |
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.
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.
There's a hard coded path in here?
void vscode.commands.executeCommand('vscode.open', filePath) | ||
if (!workspaceRootUri) { | ||
throw new Error('Failed to open file: missing workspace') | ||
filePath = 'lib\\main.dart' |
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.
???
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.
😱
Thanks for catching this. I've added a test that clicks one of these links and verifies an editor tab opens. The test is broken before removing this and passing on Windows when I removed this.
However, on Mac/Linux it's failing because apparently we have a full path without the leading slash:
Looking into that..
Ok, I tracked down the Linux/macOS test failures down to this code which is removing the leading slash from absolute file paths: cody/vscode/src/chat/chat-view/chat-helpers.ts Lines 74 to 77 in bcd49b3
It's not clear to me what the purpose of this is.. on Windows it's not being done and the tests are passing (although it's not clear to me if we wanted absolute or relative paths in the context file list). On Linux/Mac this is stripping the first I think this needs some input from someone who is more familiar with this (perhaps @abeatrix ?). And I know I've said this before, but I think we need to get better at being very explicit with comments on all "filename-like" fields what they really are... Are they URI paths (always forward slashes), native paths (backslashes on Windows), absolute, relative (if so, relative to what). |
@beyang the code quoted above was added in c958112 but it's a big change so I don't know if it was just moved/copied from elsewhere. If you authored it, do you remember what the reason was for just removing the first It's causing issues because it looks like a relative path not absolute, and since Windows paths don't start with |
The test here will be impacted by the question at #2408 - it turns out user-selected files weren't intended to show up here, so the test added for this issue won't work once they're filtered out (when #2408 lands). Depending on the response there, we may need to change the test for this (assuming the original issue is even still valid with that change). |
This decision was reverted in #2679 so user-mentioned files will show up again. However this change might be impacted by #2653 so I'll come back to this after that merges. |
This change is no longer necessary, the big was already fixed on main by changes @sqs made to tidy up use of paths vs URIs etc. :-) 2400.mp4 |
Fixes #2399 by removing a duplicate call to open a file which expects a file URI but was given a path, and only tries to join a path with the workspace URI if it's a relative path.
fix_click.mp4
I'm not certain if there really should be absolute paths in this list if things are inside my workspace, but it probably makes sense for this code to tolerate them.
@kalanchan
Test plan
@
-mention a file on Windows