From 2670607006cf20866d30c305894b794491cea097 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Thu, 22 Dec 2022 20:38:56 +0000 Subject: [PATCH] refactor(vim): update the lsp config Remove old servers that don't get used any more. Move config into a table for better visibility on what servers are installed and their configs. --- site-modules/core/files/vim/plugin/lsp.lua | 80 ++++++++++------------ 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/site-modules/core/files/vim/plugin/lsp.lua b/site-modules/core/files/vim/plugin/lsp.lua index 18f4cd0..ab50880 100644 --- a/site-modules/core/files/vim/plugin/lsp.lua +++ b/site-modules/core/files/vim/plugin/lsp.lua @@ -1,6 +1,32 @@ local lspconfig = require("lspconfig") -local on_attach = function(client, bufnr) +local servers = { + -- Language servers for the day to day web development, could probably think + -- about loosing the html and css one and living with typescript and emmet + tsserver = {}, + html = {}, + cssls = {}, + emmet_ls = { + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "scss", "eruby" }, + }, + -- Ruby + solargraph = {}, + -- Rust + rust_analyzer = {}, + -- Lua for the vim config and plugin dev + sumneko_lua = { + settings = { + Lua = { + runtime = { version = "LuaJIT" }, + diagnostics = { globals = { "vim" } }, + workspace = { library = vim.api.nvim_get_runtime_file("", true) }, + telemetry = { enable = false }, + }, + }, + }, +} + +local on_attach = function(_, bufnr) vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") local opts = { noremap = true, silent = true } @@ -13,57 +39,21 @@ local on_attach = function(client, bufnr) vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) - -- TODO(ade): Sort out space. This will conflict with the leader key - vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) end local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) capabilities.textDocument.completion.completionItem.snippetSupport = true -local servers = { "tsserver", "intelephense", "psalm", "gopls", "html", "cssls", "solargraph", "rust_analyzer" } -for _, lsp in ipairs(servers) do - lspconfig[lsp].setup({ - on_attach = on_attach, - capabilities = capabilities, - init_options = { - usePlaceholders = true, - }, - }) +for lsp, config in pairs(servers) do + config["on_attach"] = on_attach + config["capabilities"] = capabilities + config["init_options"] = { usePlaceholders = true } + + lspconfig[lsp].setup(config) end -lspconfig.emmet_ls.setup({ - on_attach = on_attach, - capabilities = capabilities, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "scss", "eruby" }, - init_options = { - usePlaceholders = true, - }, -}) - -lspconfig.sumneko_lua.setup({ - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }, -}) - -- Change the diagnostic signs vim.fn.sign_define("DiagnosticSignHint", { text = "➤", texthl = "DiagnosticSignHint", numhl = "DiagnosticSignHint" }) vim.fn.sign_define("DiagnosticSignInfo", { text = "ℹ", texthl = "DiagnosticSignInfo", numhl = "DiagnosticSignInfo" })