From ea69362bfd34d4a4216207c4274e0c31e8e3147e Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Fri, 14 Oct 2022 18:51:54 -0500 Subject: feat(nvim): move lsp configs into seperate module --- nvim/.config/nvim/lua/tobyvin/lsp/init.lua | 118 +++++++++++++++++++-- nvim/.config/nvim/lua/tobyvin/plugins.lua | 106 +++++++++--------- nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua | 3 + .../.config/nvim/lua/tobyvin/plugins/lspconfig.lua | 100 ++--------------- nvim/.config/nvim/lua/tobyvin/plugins/neodev.lua | 22 ---- .../nvim/lua/tobyvin/plugins/rust-tools.lua | 45 +++----- 6 files changed, 180 insertions(+), 214 deletions(-) diff --git a/nvim/.config/nvim/lua/tobyvin/lsp/init.lua b/nvim/.config/nvim/lua/tobyvin/lsp/init.lua index b1e46bd..513b2c0 100644 --- a/nvim/.config/nvim/lua/tobyvin/lsp/init.lua +++ b/nvim/.config/nvim/lua/tobyvin/lsp/init.lua @@ -73,20 +73,116 @@ lsp.on_attach = function(client, bufnr) vim.api.nvim_exec_autocmds("User", { pattern = "LspAttach", data = { client_id = client.id } }) end -lsp.config = function(config) - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities.textDocument.completion.completionItem.snippetSupport = true - capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) - - return vim.tbl_deep_extend("keep", config or {}, { - capabilities = capabilities, - on_attach = lsp.on_attach, - }) -end +lsp.default_config = { + on_attach = lsp.on_attach, + capabilities = vim.lsp.protocol.make_client_capabilities(), +} + +lsp.configs = { + bashls = {}, + taplo = {}, + yamlls = {}, + tsserver = {}, + pylsp = { + settings = { + pylsp = { + plugins = { + autopep8 = { + enabled = false, + }, + yapf = { + enabled = false, + }, + pylint = { + enabled = true, + }, + }, + }, + }, + }, + cssls = {}, + cssmodules_ls = {}, + stylelint_lsp = {}, + ccls = {}, + gopls = { + cmd = { "gopls", "serve" }, + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + }, + }, + }, + ["rust-analyzer"] = { + standalone = true, + settings = { + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + }, + checkOnSave = { + command = "clippy", + }, + }, + }, + }, + sumneko_lua = { + settings = { + Lua = { + completion = { + callSnippet = "Replace", + }, + diagnostics = { + globals = { "vim", "packer_plugins" }, + }, + format = { + enable = false, + }, + telemetry = { + enable = false, + }, + }, + }, + }, + texlab = { + settings = { + texlab = { + build = { + args = { + "-pdf", + "-interaction=nonstopmode", + "-synctex=1", + string.format("-auxdir=%s/aux", vim.fn.getcwd()), + string.format("-outdir=%s/out", vim.fn.getcwd()), + "-emulate-aux-dir", + "%f", + }, + onSave = true, + }, + chktex = { + onEdit = true, + onOpenAndSave = true, + }, + auxDirectory = string.format("%s/aux", vim.fn.getcwd()), + latexindent = { + ["local"] = string.format("%s/latexindent/indentconfig.yaml", vim.env.XDG_CONFIG_HOME), + modifyLineBreaks = true, + }, + }, + }, + on_attach = function(client, bufnr) + vim.g.tex_flavor = "latex" + vim.opt.spell = true + lsp.on_attach(client, bufnr) + end, + }, +} lsp.setup = function() lsp.handlers.setup() - require("tobyvin.lsp.diagnostics").setup() + lsp.diagnostics.setup() end return lsp diff --git a/nvim/.config/nvim/lua/tobyvin/plugins.lua b/nvim/.config/nvim/lua/tobyvin/plugins.lua index bacdae2..e161de8 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins.lua @@ -121,63 +121,6 @@ M.plugins = function(use) end, }) - use({ - "williamboman/mason-lspconfig.nvim", - after = "mason.nvim", - requires = { - "williamboman/mason.nvim", - }, - config = function() - require("tobyvin.plugins.mason-lspconfig").setup() - end, - }) - - use({ - "neovim/nvim-lspconfig", - after = "mason-lspconfig.nvim", - requires = { - "ray-x/lsp_signature.nvim", - "SmiteshP/nvim-navic", - "barreiroleo/ltex-extra.nvim", - }, - config = function() - require("tobyvin.plugins.lspconfig").setup() - end, - }) - - use({ - "folke/neodev.nvim", - after = "nvim-lspconfig", - requires = { - "neovim/nvim-lspconfig", - }, - config = function() - require("tobyvin.plugins.neodev").setup() - end, - }) - - use({ - "simrat39/rust-tools.nvim", - after = "nvim-lspconfig", - requires = { - "neovim/nvim-lspconfig", - }, - config = function() - require("tobyvin.plugins.rust-tools").setup() - end, - }) - - use({ - "brymer-meneses/grammar-guard.nvim", - after = "nvim-lspconfig", - requires = { - "neovim/nvim-lspconfig", - }, - config = function() - require("grammar-guard").init() - end, - }) - use({ "hrsh7th/nvim-cmp", requires = { @@ -229,6 +172,55 @@ M.plugins = function(use) end, }) + use({ + "williamboman/mason-lspconfig.nvim", + after = "mason.nvim", + requires = { + "williamboman/mason.nvim", + }, + config = function() + require("tobyvin.plugins.mason-lspconfig").setup() + end, + }) + + use({ + "folke/neodev.nvim", + config = function() + require("tobyvin.plugins.neodev").setup() + end, + }) + + use({ + "simrat39/rust-tools.nvim", + requires = { + "neovim/nvim-lspconfig", + }, + config = function() + require("tobyvin.plugins.rust-tools").setup() + end, + }) + + use({ + "neovim/nvim-lspconfig", + after = { + "mason-lspconfig.nvim", + "neodev.nvim", + "rust-tools.nvim", + "cmp-nvim-lsp", + }, + requires = { + "folke/neodev.nvim", + "simrat39/rust-tools.nvim", + "hrsh7th/cmp-nvim-lsp", + "ray-x/lsp_signature.nvim", + "SmiteshP/nvim-navic", + "barreiroleo/ltex-extra.nvim", + }, + config = function() + require("tobyvin.plugins.lspconfig").setup() + end, + }) + use({ "kevinhwang91/nvim-bqf", requires = { diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua b/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua index 88b546f..2c2fe18 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/cmp.lua @@ -1,3 +1,4 @@ +local lsp = require("tobyvin.lsp") local M = {} M.enabled = function() @@ -21,6 +22,8 @@ M.setup = function() return end + lsp.default_config.capabilities = require("cmp_nvim_lsp").update_capabilities(lsp.default_config.capabilities) + cmp.setup({ enabled = M.enabled, snippet = { diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua b/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua index 1b9a373..3d62229 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/lspconfig.lua @@ -1,5 +1,4 @@ local lsp = require("tobyvin.lsp") -local utils = require("tobyvin.utils") local M = {} M.setup = function() @@ -9,100 +8,13 @@ M.setup = function() return end - lspconfig.bashls.setup(lsp.config()) + lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, lsp.default_config) - lspconfig.taplo.setup(lsp.config()) - - lspconfig.yamlls.setup(lsp.config({ - settings = { - yaml = { - editor = { - formatOnType = true, - }, - format = { - enable = true, - }, - }, - redhat = { - telemetry = { - enabled = false, - }, - }, - }, - })) - - lspconfig.tsserver.setup(lsp.config()) - - lspconfig.pylsp.setup(lsp.config({ - settings = { - pylsp = { - plugins = { - autopep8 = { - enabled = false, - }, - yapf = { - enabled = false, - }, - pylint = { - enabled = true, - }, - }, - }, - }, - })) - - lspconfig.cssls.setup(lsp.config()) - - lspconfig.cssmodules_ls.setup(lsp.config()) - - lspconfig.stylelint_lsp.setup(lsp.config()) - - lspconfig.ccls.setup(lsp.config()) - - lspconfig.gopls.setup(lsp.config({ - cmd = { "gopls", "serve" }, - settings = { - gopls = { - analyses = { - unusedparams = true, - }, - staticcheck = true, - }, - }, - })) - - lspconfig.texlab.setup(lsp.config({ - settings = { - texlab = { - build = { - args = { - "-pdf", - "-interaction=nonstopmode", - "-synctex=1", - string.format("-auxdir=%s/aux", vim.fn.getcwd()), - string.format("-outdir=%s/out", vim.fn.getcwd()), - "-emulate-aux-dir", - "%f", - }, - onSave = true, - }, - chktex = { - onEdit = true, - onOpenAndSave = true, - }, - auxDirectory = string.format("%s/aux", vim.fn.getcwd()), - latexindent = { - ["local"] = string.format("%s/latexindent/indentconfig.yaml", vim.env.XDG_CONFIG_HOME), - modifyLineBreaks = true, - }, - }, - }, - on_attach = function(client, bufnr) - vim.g.tex_flavor = "latex" - vim.opt.spell = true - lsp.on_attach(client, bufnr) - end, - })) + for name, config in pairs(lsp.configs) do + if name ~= "rust-analyzer" then + lspconfig[name].setup(config) + end + end require("lsp_signature").setup({ bind = true, diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/neodev.lua b/nvim/.config/nvim/lua/tobyvin/plugins/neodev.lua index 5bb3fce..a2f0477 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/neodev.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/neodev.lua @@ -24,28 +24,6 @@ M.setup = function() end end, }) - - local lsp = require("tobyvin.lsp") - local lspconfig = require("lspconfig") - - lspconfig.sumneko_lua.setup(lsp.config({ - settings = { - Lua = { - completion = { - callSnippet = "Replace", - }, - diagnostics = { - globals = { "vim", "packer_plugins" }, - }, - format = { - enable = false, - }, - telemetry = { - enable = false, - }, - }, - }, - })) end return M diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua b/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua index 000ce23..b8a4456 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua @@ -12,39 +12,24 @@ M.setup = function() return end - rust_tools.setup({ - server = lsp.config({ - standalone = true, - settings = { - ["rust-analyzer"] = { - cargo = { - allFeatures = true, - }, - checkOnSave = { - command = "clippy", - }, - }, - }, - on_attach = function(client, bufnr) - lsp.on_attach(client, bufnr) + lsp.configs["rust-analyzer"].on_attach = function(client, bufnr) + lsp.on_attach(client, bufnr) + + local runnables = rust_tools.runnables.runnables + local debuggables = rust_tools.debuggables.debuggables + local open_cargo_toml = rust_tools.open_cargo_toml.open_cargo_toml + local external_docs = rust_tools.external_docs.open_external_docs - local runnables = rust_tools.runnables.runnables - local debuggables = rust_tools.debuggables.debuggables - local open_cargo_toml = rust_tools.open_cargo_toml.open_cargo_toml - local external_docs = rust_tools.external_docs.open_external_docs - local run_cargo_cmd = function() - utils.job.cmd("cargo") - end + utils.keymap.group("n", "r", { desc = "Run" }) + vim.keymap.set("n", "rr", runnables, { desc = "Runnables", buffer = bufnr }) + vim.keymap.set("n", "rd", debuggables, { desc = "Debug", buffer = bufnr }) + vim.keymap.set("n", "ro", open_cargo_toml, { desc = "Open Cargo.toml", buffer = bufnr }) - utils.keymap.group("n", "r", { desc = "Run" }) - vim.keymap.set("n", "rr", runnables, { desc = "Runnables", buffer = bufnr }) - vim.keymap.set("n", "rd", debuggables, { desc = "Debug", buffer = bufnr }) - vim.keymap.set("n", "ro", open_cargo_toml, { desc = "Open Cargo.toml", buffer = bufnr }) - vim.keymap.set("n", "rc", run_cargo_cmd, { desc = "Command", buffer = bufnr }) + utils.documentation.register("rust", external_docs) + end - utils.documentation.register("rust", external_docs) - end, - }), + rust_tools.setup({ + server = lsp.configs["rust-analyzer"], dap = { adapter = require("rust-tools.dap").get_codelldb_adapter(M.codelldb, M.liblldb), }, -- cgit v1.2.3-70-g09d2