golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.91k stars 758 forks source link

go.goroot incorrectly resolve homedir on no-windows #3586

Open pjw91 opened 3 weeks ago

pjw91 commented 3 weeks ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - * Check your installed extensions to get the version of the VS Code Go extension - * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. -

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

{"go.goroot": "~bbb/.goenv/versions/1.23.0"}

Describe the bug

When running VSCode as user aaa with the config listed above, a notification says "cannot find go binary in /home/aaa/bbb/.goenv/versions/1.23.0".

Steps to reproduce the behavior:

  1. set the config listed aboved
  2. enter a golang project

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Diagnosis

In setGOROOTEnvVar > resolvePath > resolveHomeDir, the function resolveHomeDir merely replace the character ~ to $HOME without consulting the /etc/passwd to get the homedir of user:bbb (the directory ~bbb refers to).

findleyr commented 2 weeks ago

Thank you for diagnosis. It sounds like the handling for ~ is ad-hoc, and does not support the ~bbb syntax. This is very unlikely to get fixed any time soon. Sorry.