From e7ec620b722e3bc1e3bdd92b65345d6b43ae64e4 Mon Sep 17 00:00:00 2001 From: winston Date: Wed, 21 Jun 2023 23:44:34 +0200 Subject: [PATCH] feat: rework lsp setup --- home/apps/neovim.nix | 4 +- home/apps/neovim/lua/lsp/go.lua | 5 +-- home/apps/neovim/lua/lsp/init.lua | 22 +++------- home/apps/neovim/lua/lsp/ltex.lua | 25 ++++++++++++ home/apps/neovim/lua/lsp/null-ls.lua | 9 +++-- home/apps/neovim/lua/lsp/validation.lua | 24 ++++++----- home/apps/neovim/lua/lsp/webdev.lua | 47 +++++++++++----------- home/apps/neovim/lua/plugins/telescope.lua | 4 +- 8 files changed, 80 insertions(+), 60 deletions(-) create mode 100644 home/apps/neovim/lua/lsp/ltex.lua diff --git a/home/apps/neovim.nix b/home/apps/neovim.nix index 6558d21..a0134a9 100644 --- a/home/apps/neovim.nix +++ b/home/apps/neovim.nix @@ -53,7 +53,9 @@ nodePackages.intelephense nodePackages.typescript nodePackages.typescript-language-server - nodePackages.vscode-json-languageserver + nodePackages.vscode-css-languageserver-bin + nodePackages.vscode-html-languageserver-bin + nodePackages.vscode-json-languageserver-bin nodePackages.yaml-language-server yarn diff --git a/home/apps/neovim/lua/lsp/go.lua b/home/apps/neovim/lua/lsp/go.lua index 6058d00..1c4b16d 100644 --- a/home/apps/neovim/lua/lsp/go.lua +++ b/home/apps/neovim/lua/lsp/go.lua @@ -11,10 +11,7 @@ M.setup = function(opts) breakpoint = " ", currentpos = " ", }, - lsp_cfg = { - on_attach = opts.on_attach, - capabilities = opts.capabilities, - }, + lsp_cfg = opts, lsp_gofumpt = true, lsp_keymaps = false, lsp_codelens = true, diff --git a/home/apps/neovim/lua/lsp/init.lua b/home/apps/neovim/lua/lsp/init.lua index d75d624..bac13f9 100644 --- a/home/apps/neovim/lua/lsp/init.lua +++ b/home/apps/neovim/lua/lsp/init.lua @@ -100,7 +100,7 @@ cmp.setup({ }, }) -cmp.setup.filetype("gitcommit", { +cmp.setup.filetype({ "gitcommit", "NeogitCommitMessage" }, { sources = cmp.config.sources({ { name = "cmp_git" }, }, { @@ -158,32 +158,20 @@ vim.api.nvim_create_autocmd("LspAttach", { end, }) -lspconfig.ltex.setup({ - capabilities = capabilities, - on_attach = function() - require("ltex_extra").setup({ - load_langs = { "en-US", "de-AT" }, - init_check = true, - path = vim.fn.stdpath("data") .. "/dictionary", - }) - end, - settings = { - ltex = {}, - }, -}) - -- register jq for jqls vim.cmd([[au BufRead,BufNewFile *.jq setfiletype jq]]) local common = { capabilities = capabilities } require("lsp.go").setup(common) +require("lsp.ltex").setup(common) require("lsp.helm-ls") require("lsp.null-ls") require("lsp.validation").setup(common) require("lsp.webdev").setup(common) -require("py_lsp").setup(common) -require("rust-tools").setup({ server = common }) +-- external dependencies +pcall(require("py_lsp").setup, common) +pcall(require("rust-tools").setup, { server = common }) local servers = { "astro", diff --git a/home/apps/neovim/lua/lsp/ltex.lua b/home/apps/neovim/lua/lsp/ltex.lua new file mode 100644 index 0000000..7a402fd --- /dev/null +++ b/home/apps/neovim/lua/lsp/ltex.lua @@ -0,0 +1,25 @@ +local lsp_present, lspconfig = pcall(require, "lspconfig") + +if not lsp_present then + return +end + +local M = {} + +M.setup = function(opts) + lspconfig.ltex.setup({ + capabilities = opts.capabilities, + on_attach = function() + require("ltex_extra").setup({ + load_langs = { "en-US", "de-AT" }, + init_check = true, + path = vim.fn.stdpath("data") .. "/dictionary", + }) + end, + settings = { + ltex = {}, + }, + }) +end + +return M diff --git a/home/apps/neovim/lua/lsp/null-ls.lua b/home/apps/neovim/lua/lsp/null-ls.lua index 0fcb076..0bf93cd 100644 --- a/home/apps/neovim/lua/lsp/null-ls.lua +++ b/home/apps/neovim/lua/lsp/null-ls.lua @@ -1,5 +1,9 @@ --- Null LS -local null = require("null-ls") +local null_present, null = pcall(require, "null-ls") + +if not null_present then + return +end + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) null.setup({ @@ -17,7 +21,6 @@ null.setup({ null.builtins.formatting.gofumpt, null.builtins.formatting.isort, null.builtins.formatting.prettier, - -- null.builtins.formatting.rustfmt, null.builtins.formatting.shfmt, null.builtins.formatting.stylua, null.builtins.formatting.taplo, diff --git a/home/apps/neovim/lua/lsp/validation.lua b/home/apps/neovim/lua/lsp/validation.lua index 53b0371..3cd6496 100644 --- a/home/apps/neovim/lua/lsp/validation.lua +++ b/home/apps/neovim/lua/lsp/validation.lua @@ -1,21 +1,22 @@ -local lspconfig = require("lspconfig") +local lsp_present, lspconfig = pcall(require, "lspconfig") + +if not lsp_present then + return +end local M = {} M.setup = function(opts) - lspconfig.jsonls.setup({ - capabilities = opts.capabilities, - on_attach = opts.on_attach, + lspconfig.jsonls.setup(vim.tbl_extend("keep", { + cmd = { "json-languageserver", "--stdio" }, settings = { json = { schemas = require("schemastore").json.schemas(), validate = { enable = true }, }, }, - }) - lspconfig.yamlls.setup({ - capabilities = opts.capabilities, - on_attach = opts.on_attach, + }, opts)) + lspconfig.yamlls.setup(vim.tbl_extend("keep", { settings = { yaml = { completion = true, @@ -44,8 +45,13 @@ M.setup = function(opts) }, }, }, + redhat = { + telemetry = { + enabled = false, + }, + }, }, - }) + }, opts)) end return M diff --git a/home/apps/neovim/lua/lsp/webdev.lua b/home/apps/neovim/lua/lsp/webdev.lua index 4356355..1fe1d5c 100644 --- a/home/apps/neovim/lua/lsp/webdev.lua +++ b/home/apps/neovim/lua/lsp/webdev.lua @@ -1,49 +1,48 @@ -local lspconfig = require("lspconfig") +local lsp_present, lspconfig = pcall(require, "lspconfig") + +if not lsp_present then + return +end local M = {} M.setup = function(opts) - local common = { - capabilities = opts.capabilities, - on_attach = opts.on_attach, - } - lspconfig.cssls.setup(common) - lspconfig.emmet_ls.setup(common) - lspconfig.graphql.setup({ - capabilities = opts.capabilities, - on_attach = opts.on_attach, + lspconfig.cssls.setup(vim.tbl_extend("keep", { + cmd = { "css-languageserver", "--stdio" }, + }, opts)) + lspconfig.emmet.setup(opts) + lspconfig.graphql.setup(vim.tbl_extend("keep", { filetypes = { "graphql", "typescriptreact", "javascriptreact", "typescript", }, - }) - lspconfig.intelephense.setup(common) - lspconfig.tailwindcss.setup({ - capabilities = opts.capabilities, - on_attach = opts.on_attach, + }, opts)) + lspconfig.html.setup(vim.tbl_extend("keep", { + cmd = { "html-languageserver", "--stdio" }, + }, opts)) + lspconfig.intelephense.setup(opts) + lspconfig.tailwindcss.setup(vim.tbl_extend("keep", { filetypes = { "javascriptreact", "typescriptreact", "html", "css", }, - }) + }, opts)) + -- attach tsserver only when there's a 'package.json' file in the CWD - lspconfig.tsserver.setup({ - capabilities = opts.capabilities, - on_attach = opts.on_attach, + lspconfig.tsserver.setup(vim.tbl_extend("keep", { root_dir = lspconfig.util.root_pattern("package.json"), single_file_support = false, - }) + }, opts)) + -- attach deno only when there's a 'deps.ts' file in the CWD - lspconfig.denols.setup({ - capabilities = opts.capabilities, - on_attach = opts.on_attach, + lspconfig.denols.setup(vim.tbl_extend("keep", { root_dir = lspconfig.util.root_pattern("deps.ts"), single_file_support = false, - }) + }, opts)) end return M diff --git a/home/apps/neovim/lua/plugins/telescope.lua b/home/apps/neovim/lua/plugins/telescope.lua index 3757a58..e3c1da7 100644 --- a/home/apps/neovim/lua/plugins/telescope.lua +++ b/home/apps/neovim/lua/plugins/telescope.lua @@ -1,8 +1,8 @@ local bc = vim.g.bc --- stylua: ignore local no_preview = function(opts) local defaults = require("telescope.themes").get_dropdown({ + -- stylua: ignore borderchars = { { bc.horiz, bc.vert, bc.horiz, bc.vert, bc.topleft, bc.topright, bc.botright, bc.botleft }, prompt = { bc.horiz, bc.vert, " ", bc.vert, bc.topleft, bc.topright, bc.vert, bc.vert }, @@ -14,7 +14,7 @@ local no_preview = function(opts) prompt_title = false, results_title = false, }) - return vim.tbl_deep_extend("force", defaults, opts or {}) + return vim.tbl_deep_extend("keep", opts or {}, defaults) end ---@type LazySpec[]