From 1e18e2d419496ac4ee62f8e2074497d038e43cca Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Sun, 20 Oct 2024 03:40:10 +0200 Subject: [PATCH] Change to blink over cmp, improve mason so that we don't need configs for each language server. We only override the set keys in the custom lsp config if it exists, otherwise we rely on the default one from lspconfig. --- .../nvim/lua/language_servers/bashls.lua | 44 ------------- .../nvim/lua/language_servers/clangd.lua | 4 +- .../nvim/lua/language_servers/cmake.lua | 3 - .../nvim/lua/language_servers/lua_ls.lua | 30 --------- .../nvim/lua/language_servers/yamlls.lua | 1 - home/.config/nvim/lua/plugs/blink.lua | 33 ++++++++++ home/.config/nvim/lua/plugs/cmp.lua | 61 ------------------- home/.config/nvim/lua/plugs/mason_lsp.lua | 18 ++++-- 8 files changed, 49 insertions(+), 145 deletions(-) delete mode 100644 home/.config/nvim/lua/language_servers/bashls.lua delete mode 100644 home/.config/nvim/lua/language_servers/cmake.lua delete mode 100644 home/.config/nvim/lua/language_servers/lua_ls.lua delete mode 100644 home/.config/nvim/lua/language_servers/yamlls.lua create mode 100644 home/.config/nvim/lua/plugs/blink.lua delete mode 100644 home/.config/nvim/lua/plugs/cmp.lua diff --git a/home/.config/nvim/lua/language_servers/bashls.lua b/home/.config/nvim/lua/language_servers/bashls.lua deleted file mode 100644 index fdce92f..0000000 --- a/home/.config/nvim/lua/language_servers/bashls.lua +++ /dev/null @@ -1,44 +0,0 @@ -local utils = require("lspconfig.util") - -return { - default_config = { - cmd = { "bash-language-server", "start" }, - settings = { - bashIde = { - -- Glob pattern for finding and parsing shell script files in the workspace. - -- Used by the background analysis features across files. - - -- Prevent recursive scanning which will cause issues when opening a file - -- directly in the home directory (e.g. ~/foo.sh). - -- - -- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)". - globPattern = vim.env.GLOB_PATTERN or "**/*@(.sh|.inc|.bash|.command|.zsh|zshrc|zsh_*)", - }, - bash = { - format = { - enable = true, - shell = "shfmt", - args = { - "-i", - "4", - "-bn", - "-ci" - } - }, - ignorePatterns = { - "node_modules", - ".git" - }, - lint = { - enable = true - }, - trace = { - server = "verbose" - }, - }, - }, - filetypes = { "sh", "zsh" }, - root_dir = utils.find_git_ancestor, - single_file_support = true, - }, -} diff --git a/home/.config/nvim/lua/language_servers/clangd.lua b/home/.config/nvim/lua/language_servers/clangd.lua index c66f95a..6fcacca 100644 --- a/home/.config/nvim/lua/language_servers/clangd.lua +++ b/home/.config/nvim/lua/language_servers/clangd.lua @@ -78,7 +78,7 @@ local default_capabilities = { editsNearCursor = true, }, }, - offsetEncoding = { "utf-8", "utf-16" }, + offsetEncoding = { "utf-16" }, } return { @@ -101,8 +101,8 @@ return { return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) end, single_file_support = true, - capabilities = default_capabilities, }, + capabilities = default_capabilities, docs = { description = [[ https://clangd.llvm.org/installation.html diff --git a/home/.config/nvim/lua/language_servers/cmake.lua b/home/.config/nvim/lua/language_servers/cmake.lua deleted file mode 100644 index b30bcbd..0000000 --- a/home/.config/nvim/lua/language_servers/cmake.lua +++ /dev/null @@ -1,3 +0,0 @@ -return { - -} diff --git a/home/.config/nvim/lua/language_servers/lua_ls.lua b/home/.config/nvim/lua/language_servers/lua_ls.lua deleted file mode 100644 index fcc74e5..0000000 --- a/home/.config/nvim/lua/language_servers/lua_ls.lua +++ /dev/null @@ -1,30 +0,0 @@ -return { - on_init = function(client) - local path = client.workspace_folders[1].name - if not vim.loop.fs_stat(path .. "/.luarc.json") and not vim.loop.fs_stat(path .. "/.luarc.jsonc") then - client.config.settings = vim.tbl_deep_extend("force", client.config.settings, { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using - -- (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - -- Make the server aware of Neovim runtime files - workspace = { - checkThirdParty = false, - library = { - vim.env.VIMRUNTIME, - -- "${3rd}/luv/library" - -- "${3rd}/busted/library", - }, - -- or pull in all of 'runtimepath'. NOTE: this is a lot slower - -- library = vim.api.nvim_get_runtime_file("", true) - }, - }, - }) - - client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) - end - return true - end -} diff --git a/home/.config/nvim/lua/language_servers/yamlls.lua b/home/.config/nvim/lua/language_servers/yamlls.lua deleted file mode 100644 index a564707..0000000 --- a/home/.config/nvim/lua/language_servers/yamlls.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/home/.config/nvim/lua/plugs/blink.lua b/home/.config/nvim/lua/plugs/blink.lua new file mode 100644 index 0000000..ff2b0a4 --- /dev/null +++ b/home/.config/nvim/lua/plugs/blink.lua @@ -0,0 +1,33 @@ +return { + "saghen/blink.cmp", + lazy = false, -- lazy loading handled internally + + -- use a release tag to download pre-built binaries + version = "v0.*", + -- OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust + -- build = 'cargo build --release', + -- On musl libc based systems you need to add this flag + -- build = 'RUSTFLAGS="-C target-feature=-crt-static" cargo build --release', + -- If you use nix, you can build from source using latest nightly rust with: + -- build = 'nix run .#build-plugin', + + ---@module "blink.cmp" + ---@type blink.cmp.Config + opts = { + highlight = { + -- sets the fallback highlight groups to nvim-cmp's highlight groups + -- useful for when your theme doesn't support blink.cmp + -- will be removed in a future release, assuming themes add support + use_nvim_cmp_as_default = true, + }, + -- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- adjusts spacing to ensure icons are aligned + nerd_font_variant = "mono", + + -- experimental auto-brackets support + -- accept = { auto_brackets = { enabled = true } } + + -- experimental signature help support + -- trigger = { signature_help = { enabled = true } } + } +} diff --git a/home/.config/nvim/lua/plugs/cmp.lua b/home/.config/nvim/lua/plugs/cmp.lua deleted file mode 100644 index 513a2f4..0000000 --- a/home/.config/nvim/lua/plugs/cmp.lua +++ /dev/null @@ -1,61 +0,0 @@ -return { - "hrsh7th/nvim-cmp", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - }, - event = "InsertEnter", - config = function() - local cmp = require("cmp") - - cmp.setup({ - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources( - { - { - name = "nvim_lsp", - entry_filter = function(entry) - return cmp.lsp.CompletionItemKind.Snippet ~= entry:get_kind() - end, - }, - }) - }) - - -- Set configuration for specific filetype. - cmp.setup.filetype("gitcommit", { - sources = cmp.config.sources( - { - { name = "git" }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). - }, - { - { name = "buffer" }, - }) - }) - - -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). - cmp.setup.cmdline({ "/", "?" }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer" } - } - }) - - -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). - cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "path" } - }, { - { name = "cmdline" } - }), - matching = { disallow_symbol_nonprefix_matching = false } - }) - end, -} diff --git a/home/.config/nvim/lua/plugs/mason_lsp.lua b/home/.config/nvim/lua/plugs/mason_lsp.lua index 29f909c..a76fbba 100644 --- a/home/.config/nvim/lua/plugs/mason_lsp.lua +++ b/home/.config/nvim/lua/plugs/mason_lsp.lua @@ -1,15 +1,25 @@ local utils = require("utils") +local function get_lsp_conf(default_conf, server_name) + local result, custom_conf = pcall(require, "language_servers/" .. server_name) + if not result or not custom_conf then + return default_conf + end + + return custom_conf +end + local function setup_lsp(server_names) - local capabilities = require("cmp_nvim_lsp").default_capabilities() - capabilities.offsetEncoding = { "utf-16" } local lspconfig = require("lspconfig") for _, server_name in ipairs(server_names) do local server = lspconfig[server_name] if server then - local server_conf = require("language_servers/" .. server_name) - capabilities.textDocument.completion.completionItem.snippetSupport = false + local server_conf = get_lsp_conf(server, server_name) + + local capabilities = server_conf.capabilities or {} server_conf.capabilities = capabilities + + capabilities.offsetEncoding = { "utf-16" } server_conf.on_attach = function(client, bufnr) vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })