nvim-config

Log | Files | Refs | Submodules | README

commit 44a79746619eff8f398378be3fefce788f20232f
parent 8cb6b99cc8e140f07e8c4f5661c62c707da5dcea
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Tue, 26 Jul 2022 14:53:07 +0200

Move away from lspconfig

Diffstat:
Mlua/lsp_config.lua | 212++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mlua/plugins.lua | 4++--
2 files changed, 130 insertions(+), 86 deletions(-)

diff --git a/lua/lsp_config.lua b/lua/lsp_config.lua @@ -1,9 +1,9 @@ -local lsp = require 'lspconfig' +require "mason".setup {} vim.diagnostic.config { virtual_text = false, severity_sort = true, - signs = { enable = true }, + signs = true, virtual_lines = false } @@ -186,6 +186,24 @@ local function texlab_attach(client, bufnr) on_attach(client, bufnr) end +local augroup = vim.api.nvim_create_augroup("User_LSP", {}) + +local function setup_lsp(name, filetypes, command, config) + local cfg = vim.deepcopy(config) + cfg.name = name + cfg.cmd = command + vim.api.nvim_create_autocmd("Filetype", { + pattern = filetypes, + group = augroup, + callback = function() + for name, func in pairs(config.ucommands or {}) do + vim.api.nvim_create_user_command(name, func) + end + vim.lsp.start(cfg) + end + }) +end + -- System lsps local capabilities = vim.lsp.protocol.make_client_capabilities() @@ -193,107 +211,133 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true local default_config = { capabilities = capabilities, on_attach = on_attach } local system_lsps = { - hls = default_config, - ocamllsp = default_config, + hls = { + filetypes = { "haskell" }, + cfg = default_config, + }, - zk = { - on_attach = on_attach, - capabilities = capabilities, - cmd = { "zk", "lsp" }, - filetypes = { 'markdown' }, - root_dir = function() - return vim.loop.cwd() - end, - } -} + ocamllsp = { + filetypes = { "ocaml" }, + cfg = default_config, + }, -for lname, config in pairs(system_lsps) do - lsp[lname].setup(config) -end + clangd = { + filetypes = { "c", "cpp" }, + cfg = default_config, + }, --- Lsp installer lsps + pylsp = { + filetypes = { "python" }, + cfg = default_config, + }, -require("nvim-lsp-installer").setup {} + rnix = { + filetypes = { "nix" }, + cfg = default_config, + }, -local lsps = { - -- Default configs - clangd = default_config, - als = default_config, - pylsp = default_config, - rnix = default_config, - vimls = default_config, - gopls = default_config, + vimls = { + filetypes = { "vim" }, + cfg = default_config, + }, + + gopls = { + filetypes = { "go" }, + cfg = default_config, + }, -- Special cases + zk = { + command = { "zk", "lsp" }, + filetypes = { 'markdown' }, + cfg = { + on_attach = on_attach, + capabilities = capabilities, + root_dir = vim.loop.cwd(), + } + }, + rust_analyzer = { - capabilities = capabilities, - on_attach = on_attach, - cmd = { "rustup", "run", "nightly", "rust-analyzer" } + filetypes = { "rust" }, + cmd = { "rustup", "run", "nightly", "rust-analyzer" }, + cfg = default_config, }, - sumneko_lua = (function() + + ["lua-language-server"] = (function() return { - capabilities = capabilities, - on_attach = on_attach, - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = vim.split(package.path, ';'), - }, - 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), - checkThirdParty = false, - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, + filetypes = { "lua" }, + cfg = { + capabilities = capabilities, + on_attach = on_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = vim.split(package.path, ';'), + }, + 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), + checkThirdParty = false, + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, }, }, - }, + } } end)(), + texlab = { - capabilities = capabilities, - on_attach = texlab_attach, - on_init = function(client) - client.cleanAuxiliary = function(uri) - uri = uri or vim.uri_from_bufnr(vim.api.nvim_get_current_buf()) - client.request("workspace/executeCommand", - { command = "texlab.cleanAuxiliary", arguments = { document = { uri = uri } } }) - end + filetypes = { "tex", "bib" }, + cfg = { + capabilities = capabilities, + on_attach = texlab_attach, + on_init = function(client) + client.cleanAuxiliary = function(uri) + uri = uri or vim.uri_from_bufnr(vim.api.nvim_get_current_buf()) + client.request("workspace/executeCommand", + { command = "texlab.cleanAuxiliary", arguments = { document = { uri = uri } } }) + end - client.cleanArtifacts = function(uri) - uri = uri or vim.uri_from_bufnr(vim.api.nvim_get_current_buf()) - client.request("workspace/executeCommand", - { command = "texlab.cleanArtifacts", arguments = { document = { uri = uri } } }) - end - end, - settings = { - texlab = { - build = { - onSave = true, - }, - forwardSearch = { - executable = "zathura", - args = { "--synctex-forward", "%l:1:%f", "%p" } - }, - latex = { - rootDirectory = ".", - }, - } + client.cleanArtifacts = function(uri) + uri = uri or vim.uri_from_bufnr(vim.api.nvim_get_current_buf()) + client.request("workspace/executeCommand", + { command = "texlab.cleanArtifacts", arguments = { document = { uri = uri } } }) + end + end, + settings = { + texlab = { + build = { + onSave = true, + }, + forwardSearch = { + executable = "zathura", + args = { "--synctex-forward", "%l:1:%f", "%p" } + }, + latex = { + rootDirectory = ".", + }, + } + }, }, - }, + } } -for lname, config in pairs(lsps) do - lsp[lname].setup(config) +for lname, config in pairs(system_lsps) do + if not config.filetypes then + vim.notify(string.format("No filetypes defined for %s", lname)) + else + setup_lsp(lname, config.filetypes, config.command or { lname }, config.cfg) + end end require 'ltex-ls'.setup { diff --git a/lua/plugins.lua b/lua/plugins.lua @@ -54,8 +54,8 @@ return packer.startup(function(use) require("lsp_lines").setup() end, } - use { 'neovim/nvim-lspconfig', requires = "williamboman/nvim-lsp-installer" } - localuse { 'vigoux/ltex-ls.nvim', requires = 'neovim/nvim-lspconfig' } + use { "williamboman/mason.nvim" } + localuse { 'vigoux/ltex-ls.nvim' } -- Treesitter related localuse 'nvim-treesitter/nvim-treesitter'