Closed bigluck closed 1 year ago
Have you looked into the "go.alternateTools"
setting? Assuming that the extension currently requires gopls
, dlv
, and gotests
, gomodifytags
depending on your workflow, I think you just need to configure the absolute paths for a couple of tools. Note that go-outline
, godef
, etc are no longer needed. (see https://github.com/golang/vscode-go/issues/2799 for details)
You can even specify the full path of the go
command line with "go.alternateTools"
.
Let us know if this doesn't work for you.
Lastly, "go.gopath"
is to configure GOPATH
. That shouldn't point to the path that contain standard libraries or go command.
Waw, I completely missed that config, thanks so much @hyangah !
Now I have something like:
{
"go.alternateTools": {
"go": "${workspaceRoot}/.devenv/profile/bin/go",
"gomodifytags": "${workspaceRoot}/.devenv/profile/bin/gomodifytags",
"godef": "${workspaceRoot}/.devenv/profile/bin/godef",
"gofmt": "${workspaceRoot}/.devenv/profile/bin/gofmt",
"goimports": "${workspaceRoot}/.devenv/profile/bin/goimports",
"gopls": "${workspaceRoot}/.devenv/profile/bin/gopls",
"godoc": "${workspaceRoot}/.devenv/profile/bin/godoc",
"gotests": "${workspaceRoot}/.devenv/profile/bin/gotests",
"godex": "${workspaceRoot}/.devenv/profile/bin/godex",
"dlv": "${workspaceRoot}/.devenv/profile/bin/dlv"
},
"go.formatTool": "gofmt",
"editor.formatOnSave": true
}
And it works! Is there any room for additional optimization? Essentially all the binaries are in the same folder (${workspaceRoot}/.devenv/profile/bin/
), but looks like I have to manually define all of them.
Thanks
Good to know that that works. As I mentioned earlier, godef
, gofmt
, goimports
, godoc
, godex
are not used by this extension, so you can delete the entries.
Is your feature request related to a problem? Please describe. Using devenv in conjunction with nix makes it hard to have a "portable" and "reproducible" development environment with go & vscode-go.
devenv, when activated, will install golang and other system packages in a subshell. Env variables are updated in the sub-shell, but are not readable by VS Code.
Example of my
devenv.nix
file:With the current version of the plugin I can manually set the
go.gopath
:It points to a sandboxed folder of the golang interpreter, but that folder only contains the standard go binaries. Indeed
godef
,gopls
andgo-outline
are installed in different sendboxed folders (because this is what Nix does and what makes Nix a fully reproducible package manager):Describe the solution you'd like The easier solution is to replicate what the Python plugin does. In Python the end user can configure the full path (or just the name) of a command, as you can see in this screenshot:
This is a common problem in Python, especially when you need to run your code in a virtual environment (
python3 -m venv .venv
).By following this approach, the go plugin should be updated by exposing a configuration entry for every optional package, allowing the user to set its full path if needed (or by using as a fallback the actual value).
This will not be a breaking change but will unlock advanced usage.