diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index d076ec6..1caa531 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -43,8 +43,35 @@ return { }) opts.servers.harper_ls = {} - -- Setup function to prevent harper_ls from autostarting opts.setup = opts.setup or {} + + -- LazyVim's Go extra assumes semantic token capabilities are always present. + -- Some completion/LSP capability providers omit them, which causes: + -- attempt to index local 'semantic' (a nil value) + opts.setup.gopls = function(_, server_opts) + Snacks.util.lsp.on({ name = "gopls" }, function(_, client) + if client.server_capabilities.semanticTokensProvider then + return + end + + local semantic = client.config.capabilities + and client.config.capabilities.textDocument + and client.config.capabilities.textDocument.semanticTokens + + if semantic and semantic.tokenTypes and semantic.tokenModifiers then + client.server_capabilities.semanticTokensProvider = { + full = true, + legend = { + tokenTypes = semantic.tokenTypes, + tokenModifiers = semantic.tokenModifiers, + }, + range = true, + } + end + end) + end + + -- Setup function to prevent harper_ls from autostarting opts.setup.harper_ls = function(_, server_opts) -- Don't setup harper_ls automatically return true