vscode-go
vscode-go copied to clipboard
workspace symbol returns symbols from vendor
{
"key": "ctrl+t",
"command": "workbench.action.showAllSymbols"
}
This should have the option to exclude symbols, by excluding folders and/or files. For example, I might want to exclude the folder vendor and its contents from symbols.
Right now the setting is completely useless, as it is including any symbol from any go tool or go tool dependency.
Remotely related to https://github.com/golang/go/issues/73493
Initially opened it here: https://github.com/microsoft/vscode/issues/249388
What did I do:
My go.mod file includes the tool directive:
...
tool (
go.uber.org/nilaway/cmd/nilaway
golang.org/x/tools/cmd/deadcode
golang.org/x/tools/cmd/godoc
golang.org/x/vuln/cmd/govulncheck
mvdan.cc/gofumpt
)
...
I also vendored all dependencies:
go mod tidy
go mod vendor
My gopls settings:
"gopls": {
"formatting.gofumpt": true,
"ui.navigation.symbolScope": "workspace",
"ui.semanticTokens": true,
}
What happens:
Intellisense from vscode is working as expected, not including any vendor dependencies. ctrl+t however does show vendored symbols.
{
"key": "ctrl+t",
"command": "workbench.action.showAllSymbols"
}
What I would expect to happen:
ctrl+t should not show any symbols which are part of vendor.
Gopls already supports a setting called symbolScope that allows you to control this. The value you want is workspace.
@adonovan I did set that, and it did not work.
@adonovan I did set that, and it did not work.
Could you show the relevant portion of your gopls settings, and of the gopls RPC and server logs?
@adonovan I updated my initial issue and added more context.
gopls and gopls(server) show absolutely nothing when pressing ctrl+t.
gopls and gopls(server) show absolutely nothing when pressing ctrl+t.
Hmm... then this cannot be a gopls issue. Transferring to vscode-go issue tracker.
Sorry I completely miss this issue. I think the ctrl + T is workspace/symbol
The short answer is, workspace/symbol will yield vendor if you open the file. If you close it, it will no longer give you the vendor.
For example, if I open vendor/mvdan.cc/gofumpt/gofmt.go and search rewrite, the rewrite from main.go and from vendor will show up.
[Trace - 12:36:52 PM] Sending request 'workspace/symbol - (832)'.
Params: {
"query": "rewrite"
}
[Trace - 12:36:52 PM] Received response 'workspace/symbol - (832)' in 3ms.
Result: [
{
"location": {
"uri": "file:///.../main.go",
"range": {
"start": {
"line": 21,
"character": 4
},
"end": {
"line": 21,
"character": 11
}
}
},
"name": "rewrite",
"kind": 13,
"containerName": "helloworld"
},
{
"location": {
"uri": "file:///.../vendor/mvdan.cc/gofumpt/gofmt.go",
"range": {
"start": {
"line": 55,
"character": 1
},
"end": {
"line": 55,
"character": 12
}
}
},
"name": "rewriteRule",
"kind": 13,
"containerName": "mvdan.cc/gofumpt"
},
{
"location": {
"uri": "file:///.../vendor/mvdan.cc/gofumpt/gofmt.go",
"range": {
"start": {
"line": 248,
"character": 19
},
"end": {
"line": 248,
"character": 24
}
}
},
"name": "reporter.Write",
"kind": 6,
"containerName": "mvdan.cc/gofumpt"
}
]
But if I close it, the result will no longer shows up
[Trace - 12:38:32 PM] Sending request 'workspace/symbol - (854)'.
Params: {
"query": "rewrite"
}
[Trace - 12:38:32 PM] Received response 'workspace/symbol - (854)' in 4ms.
Result: [
{
"location": {
"uri": "file:///.../main.go",
"range": {
"start": {
"line": 21,
"character": 4
},
"end": {
"line": 21,
"character": 11
}
}
},
"name": "rewrite",
"kind": 13,
"containerName": "helloworld"
}
]
I remember similar question have shows up multiple times in the past, some of them are related to find references. Gopls will also find references of a variable in vendor if you open the go file in vendor. Basically, the area that gopls are searching is determine both by your module as well as your opened go file. So WAI I suppose?
gopls and gopls(server) show absolutely nothing when pressing ctrl+t. is because "go.trace.server": "verbose", is missing from user json settings.
The short answer is, workspace/symbol will yield vendor if you open the file. If you close it, it will no longer give you the vendor.
@h9jiang
Sadly, this is not the case. With everything closed, vendor symbols still show up, even on a fresh start of VSCode.
See screenshot below. It also works with any direct function or struct name. I just prefixed my search with templ. in order to hide corporate Symbols.
Right now the setting is completely useless, as it is including any symbol from any go tool or go tool dependency.
This is no longer the case.
However, it brings up symbols from direct dependencies. This could be desirable. It would be nice to have an exclude option.
Thanks. I think this is kind of weird.
Can you enable the trace I mentioned before by adding "go.trace.server": "verbose", to the settings.json and try to re-produce this issue? And share the trace with us. The trace will be very similar to what I have shared before. I think the most important thing is where the workspae/symbol is happening. What is the request and what is the response.
I think the gopls is handling this request.
Is the configuration you mentioned in the first comment everything you have configured?
"gopls": {
"formatting.gofumpt": true,
"ui.navigation.symbolScope": "workspace",
"ui.semanticTokens": true,
}
@h9jiang not sure if you fully got everything I mentioned.
~Right now the setting is completely useless, as it is including any symbol from any go tool or go tool dependency.~
This is no longer the case!
VSCode only brings up direct dependencies, which could be desirable.
Relating to this:
Thanks. I think this is kind of weird.
Can you enable the trace I mentioned before by adding "go.trace.server": "verbose", to the settings.json and try to re-produce this issue? And share the trace with us. The trace will be very similar to what I have shared before. I think the most important thing is where the workspae/symbol is happening. What is the request and what is the response.
I think the gopls is handling this request.
Is the configuration you mentioned in the first comment everything you have configured?
I will get back to you sometime next week when I have more time.
@adonovan @h9jiang
These are my settings.
"gopls": {
"formatting.gofumpt": true,
"ui.navigation.symbolScope": "workspace",
"ui.semanticTokens": true,
"go.ui.diagnostic.analyses": {
"nilness": true
}
},
Logs for gopls on a public repo.
I searched for uuid basically ctrl+shift+p ⇒ #uuid
My apologies for replying late, I was sick.