Skip to content

feat(cli): add coder open vscode #11191

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

Merged
merged 18 commits into from
Jan 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
convert / to \ for abs path check using filepath
  • Loading branch information
mafredri committed Jan 2, 2024
commit 747ecad74d806ebf2ac9a9f528beb2dd07ccbb62
5 changes: 3 additions & 2 deletions cli/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func isWindowsAbsPath(p string) bool {
switch {
case len(p) == 0:
return false
case p[0] == '/' || p[0] == '\\':
case p[0] == '\\':
return true
default:
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried /path/to/something, \path\to\something and C:/path/to/something which also both work in VSCode. Defaults to the drive Windows is installed on if there isn't a drive letter.

IDK how paths work in Windows containers either, unsure if they have drive letters or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'll need to play around with this some more. I was actually planning on testing with agents on Windows today, but it turns out our win template is broken atm. I know at least the "expanded directory" resolves to C:\... via test runners. I suspected / might work in VS Code but out of precaution I wanted to transform them.

Perhaps we can just make everything slash and only have the logic for detecting abs path on Windows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some handling for the cases you mentioned, and relaxed the abs requirement to include /, \. I know there are more exceptions like \\.UNC\ paths and the like, but I don't know if it's worth adding preemptive handling for that.

Copy link
Member Author

@mafredri mafredri Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I can't seem to make CI happy because Go filepath.IsAbs on windows seems to think differently? https://github.com/coder/coder/actions/runs/7262677715/job/19786347550?pr=11191#step:5:496

(I kept the fallback to filepath vs our impl. on Windows so that we could catch these types of inconsistencies, but I can just remove that if we don't care.)

Expand Down Expand Up @@ -305,11 +305,12 @@ func resolveAgentAbsPath(workingDirectory, relOrAbsPath, agentOS string, local b
return p, nil

case agentOS == "windows":
relOrAbsPath = strings.ReplaceAll(relOrAbsPath, "/", "\\")
switch {
case workingDirectory != "" && !isWindowsAbsPath(relOrAbsPath):
return windowsJoinPath(workingDirectory, relOrAbsPath), nil
case isWindowsAbsPath(relOrAbsPath):
return windowsJoinPath(relOrAbsPath), nil
return relOrAbsPath, nil
default:
return "", xerrors.Errorf("path %q not supported, use an absolute path instead", relOrAbsPath)
}
Expand Down