Refactor LSP configuration

This commit is contained in:
Oliver Davies 2024-11-20 09:17:16 +00:00
parent a181e9fe4e
commit 963f09c67f

View file

@ -1,110 +1,108 @@
local lspconfig = require "lspconfig" local cmp_nvim_lsp = require "cmp_nvim_lsp"
local nvim_status = require "lsp-status"
local handlers = require "opdavies.lsp.handlers" local handlers = require "opdavies.lsp.handlers"
local lspconfig = require "lspconfig"
require("neodev").setup {} require("neodev").setup {}
local servers = { local capabilities = cmp_nvim_lsp.default_capabilities(vim.lsp.protocol.make_client_capabilities())
bashls = true,
cssls = { lspconfig.bashls.setup {
on_attach = function(client, bufnr) capabilities = capabilities,
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(handlers.on_publish_diagnostics, {}) }
end,
},
gopls = true, lspconfig.cssls.setup {
html = true, capabilities = capabilities,
on_attach = function(_, _)
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(handlers.on_publish_diagnostics, {})
end,
}
intelephense = { lspconfig.gopls.setup {
filetypes = { "php", "module", "test", "inc" }, capabilities = capabilities,
}, }
lua_ls = { lspconfig.html.setup {
settings = { capabilities = capabilities,
Lua = { }
completion = {
callSnippet = "Replace",
},
diagnostics = { lspconfig.intelephense.setup {
globals = { "vim" }, capabilities = capabilities,
}, }
runtime = { lspconfig.lua_ls.setup {
version = "LuaJIT", capabilities = capabilities,
}, settings = {
Lua = {
telemetry = { completion = {
enabled = false, callSnippet = "Replace",
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
}, },
}, diagnostics = {
}, globals = { "vim" },
marksman = true,
nixd = {
command = { "nixd" },
settings = {
nixd = {
nixpkgs = {
expr = "import <nixpkgs> { }",
},
formatting = {
command = "nix fmt",
},
}, },
}, runtime = {
}, version = "LuaJIT",
tailwindcss = {
filetypes = { "html", "javascript", "twig", "typescript", "vue" },
settings = {
init_options = {
userLanguages = {
["html.twig"] = "html",
},
}, },
}, telemetry = {
}, enabled = false,
},
terraformls = true, workspace = {
library = vim.api.nvim_get_runtime_file("", true),
-- TODO: make this work with Vue files.
ts_ls = true,
vuels = true,
yamlls = {
settings = {
yaml = {
keyOrdering = false,
}, },
}, },
}, },
} }
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) lspconfig.marksman.setup {
capabilities = capabilities,
}
for server_name, config in pairs(servers) do lspconfig.nixd.setup {
if config == true then capabilities = capabilities,
config = {} cmd = { "nixd" },
end settings = {
nixd = {
nixpkgs = {
expr = "import <nixpkgs> { }",
},
formatting = {
command = "nix fmt",
},
},
},
}
config = vim.tbl_deep_extend("force", {}, { lspconfig.tailwindcss.setup {
capabilities = capabilities, capabilities = capabilities,
}, config) filetypes = { "html", "javascript", "twig", "typescript", "vue" },
settings = {
init_options = {
userLanguages = {
["html.twig"] = "html",
},
},
},
}
lspconfig[server_name].setup(config) lspconfig.terraformls.setup {
end capabilities = capabilities,
}
lspconfig.tsserver.setup {
capabilities = capabilities,
}
lspconfig.vuels.setup {
capabilities = capabilities,
}
lspconfig.yamlls.setup {
capabilities = capabilities,
settings = {
yaml = {
keyOrdering = false,
},
},
}
vim.diagnostic.config { vim.diagnostic.config {
float = { source = true }, float = { source = true },
@ -118,19 +116,6 @@ vim.api.nvim_create_autocmd("LspAttach", {
callback = function() callback = function()
local builtin = require "telescope.builtin" local builtin = require "telescope.builtin"
-- buf_inoremap { "<C-k>", vim.lsp.buf.signature_help }
-- buf_nnoremap { "<leader>ca", vim.lsp.buf.code_action }
-- buf_nnoremap { "<leader>d", vim.diagnostic.open_float }
-- buf_nnoremap { "<leader>rn", vim.lsp.buf.rename }
-- buf_nnoremap { "<leader>rr", "<cmd>LspRestart<cr>" }
-- buf_nnoremap { "[d", vim.diagnostic.goto_prev }
-- buf_nnoremap { "]d", vim.diagnostic.goto_next }
-- buf_nnoremap { "gD", vim.lsp.buf.declaration }
-- buf_nnoremap { "gd", handlers.definition }
-- buf_nnoremap { "gi", vim.lsp.buf.implementation }
-- buf_nnoremap { "gT", vim.lsp.buf.type_definition }
vim.keymap.set("n", "gd", builtin.lsp_definitions, { buffer = 0 }) vim.keymap.set("n", "gd", builtin.lsp_definitions, { buffer = 0 })
vim.keymap.set("n", "gr", builtin.lsp_references, { buffer = 0 }) vim.keymap.set("n", "gr", builtin.lsp_references, { buffer = 0 })
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { buffer = 0 }) vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { buffer = 0 })