The way I do it in VS Code is to do something like this from the repo root:
# Get the dev version of Go into PATH for the editor and local dev work
$ export PATH=$PWD/bin:$PATH
# Build a baseline version of go and save it to restore if things break, or for comparison
$ (cd src; GOGC=off ./make.bash) && toolstash save
# Launch VS Code with the relevant module roots, with PATH set
$ code ../go.code-workspace
Where go.code-workspace is in the folder above my checkout (as it's not in .gitignore):
{
"folders": [
{
"path": "go/src"
},
{
"path": "go/src/cmd"
},
{
"path": "go/test"
}
],
"settings": {
"editor.codeActionsOnSave": {"source.fixAll": false},
"go.lintOnSave": "off",
"go.lintTool": "staticcheck",
"gopls": {
// "ui.semanticTokens": true,
"ui.diagnostic.analyses": {
"unsafeptr": false,
"simplifycompositelit": false,
},
"ui.diagnostic.staticcheck": false,
},
"go.languageServerFlags": [
"-remote=auto;godev",
],
}
}
Which defines explicitly marks those roots for gopls, and sets a couple of settings that make editing the toolchain a little less annoying (thanks to the extra diagnostics and fixes and such).
It's entirely possible that there's an easier way to do this, or that it's already moot thanks to experimental multi-module stuff / workfile stuff. That'd be nice to know (so I can remove all of this), but for now this is what I do and I'm relatively content