Tomas Vik

Neovim - Make LSP Workspace Symbols show only workspace symbols

I copied Helix’s key mappings for showing LSP symbols. I map space+s to show buffer symbols and space+S to show workspace symbols. For showing the workspace symbols I use Telescope’s builtin.lsp_workspace_symbols picker.

But when I press space+S, I get all the symbols from all dependencies. The default gopls behaviour is to show you all available symbols, not the symbols from your code as you might expect.

Luckily, there is a symbolScope setting for gopls. It defaults to all but you can change it to workspace and then gopls only gives you symbols from your project.

This is my lspconfig:

lspconfig["gopls"].setup({
    capabilities = capabilities,
    on_attach = on_attach,
    settings = {
        gopls = {
            symbolScope = "workspace",
        }, -- when I search for symbols, I don't want to see dependencies
    },
})