vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

workspace symbol returns symbols from vendor

Open hu3bi opened this issue 6 months ago • 10 comments

{
  "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.

hu3bi avatar May 22 '25 11:05 hu3bi

Gopls already supports a setting called symbolScope that allows you to control this. The value you want is workspace.

adonovan avatar May 22 '25 19:05 adonovan

@adonovan I did set that, and it did not work.

hu3bi avatar May 23 '25 09:05 hu3bi

@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 avatar May 23 '25 15:05 adonovan

@adonovan I updated my initial issue and added more context.

gopls and gopls(server) show absolutely nothing when pressing ctrl+t.

hu3bi avatar May 27 '25 09:05 hu3bi

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.

adonovan avatar May 27 '25 17:05 adonovan

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.

Image
[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

Image
[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.

h9jiang avatar Sep 18 '25 16:09 h9jiang

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.

Image

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.

hu3bi avatar Sep 19 '25 08:09 hu3bi

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 avatar Sep 19 '25 14:09 h9jiang

@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.

hu3bi avatar Sep 21 '25 16:09 hu3bi

@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.

gopls.txt

I searched for uuid basically ctrl+shift+p ⇒ #uuid

My apologies for replying late, I was sick.

hu3bi avatar Oct 05 '25 14:10 hu3bi