refactor: LazyVim.lsp.on_attach

This commit is contained in:
Folke Lemaitre 2024-06-08 08:11:28 +02:00
parent 6098a36d92
commit 8f7ee56dab
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
6 changed files with 32 additions and 42 deletions

View file

@ -66,10 +66,8 @@ return {
-- attach cmp source whenever copilot attaches -- attach cmp source whenever copilot attaches
-- fixes lazy-loading issues with the copilot cmp source -- fixes lazy-loading issues with the copilot cmp source
LazyVim.lsp.on_attach(function(client) LazyVim.lsp.on_attach(function(client)
if client.name == "copilot" then
copilot_cmp._on_insert_enter({}) copilot_cmp._on_insert_enter({})
end end, "copilot")
end)
end, end,
}, },
}, },

View file

@ -36,11 +36,9 @@ return {
setup = { setup = {
angularls = function() angularls = function()
LazyVim.lsp.on_attach(function(client) LazyVim.lsp.on_attach(function(client)
if client.name == "angularls" then
--HACK: disable angular renaming capability due to duplicate rename popping up --HACK: disable angular renaming capability due to duplicate rename popping up
client.server_capabilities.renameProvider = false client.server_capabilities.renameProvider = false
end end, "angularls")
end)
end, end,
}, },
}, },

View file

@ -61,7 +61,6 @@ return {
-- workaround for gopls not supporting semanticTokensProvider -- workaround for gopls not supporting semanticTokensProvider
-- https://github.com/golang/go/issues/54531#issuecomment-1464982242 -- https://github.com/golang/go/issues/54531#issuecomment-1464982242
LazyVim.lsp.on_attach(function(client, _) LazyVim.lsp.on_attach(function(client, _)
if client.name == "gopls" then
if not client.server_capabilities.semanticTokensProvider then if not client.server_capabilities.semanticTokensProvider then
local semantic = client.config.capabilities.textDocument.semanticTokens local semantic = client.config.capabilities.textDocument.semanticTokens
client.server_capabilities.semanticTokensProvider = { client.server_capabilities.semanticTokensProvider = {
@ -73,8 +72,7 @@ return {
range = true, range = true,
} }
end end
end end, "gopls")
end)
-- end workaround -- end workaround
end, end,
}, },

View file

@ -1,13 +1,3 @@
LazyVim.lsp.on_attach(function(client, buffer)
if client.name == "yamlls" then
if vim.api.nvim_get_option_value("filetype", { buf = buffer }) == "helm" then
vim.schedule(function()
vim.cmd("LspStop ++force yamlls")
end)
end
end
end)
return { return {
recommended = function() recommended = function()
return LazyVim.extras.wants({ return LazyVim.extras.wants({
@ -25,9 +15,19 @@ return {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
opts = { opts = {
servers = { servers = {
yamlls = {},
helm_ls = {}, helm_ls = {},
}, },
setup = {
yamlls = function()
LazyVim.lsp.on_attach(function(client, buffer)
if vim.bo[buffer].filetype == "helm" then
vim.schedule(function()
vim.cmd("LspStop ++force yamlls")
end)
end
end, "yamlls")
end,
},
}, },
}, },
} }

View file

@ -58,11 +58,9 @@ return {
setup = { setup = {
[ruff] = function() [ruff] = function()
LazyVim.lsp.on_attach(function(client, _) LazyVim.lsp.on_attach(function(client, _)
if client.name == ruff then
-- Disable hover in favor of Pyright -- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false client.server_capabilities.hoverProvider = false
end end, ruff)
end)
end, end,
}, },
}, },

View file

@ -60,10 +60,8 @@ return {
-- Neovim < 0.10 does not have dynamic registration for formatting -- Neovim < 0.10 does not have dynamic registration for formatting
if vim.fn.has("nvim-0.10") == 0 then if vim.fn.has("nvim-0.10") == 0 then
LazyVim.lsp.on_attach(function(client, _) LazyVim.lsp.on_attach(function(client, _)
if client.name == "yamlls" then
client.server_capabilities.documentFormattingProvider = true client.server_capabilities.documentFormattingProvider = true
end end, "yamlls")
end)
end end
end, end,
}, },