From b9de21e8f878b6a2b679bbfa17a9cd312a76f56e Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Mon, 6 Jul 2026 09:49:03 +0200 Subject: [PATCH] feat: move to blink.cmp from cmp --- nvim/lua/lsp-options.lua | 2 +- nvim/lua/plugins/lsp/cmp.lua | 130 ---------------------------- nvim/lua/plugins/lsp/completion.lua | 67 ++++++++++++++ nvim/lua/plugins/lsp/lspconfig.lua | 82 ++++++++++-------- nvim/lua/plugins/style/noice.lua | 2 - 5 files changed, 112 insertions(+), 171 deletions(-) delete mode 100755 nvim/lua/plugins/lsp/cmp.lua create mode 100644 nvim/lua/plugins/lsp/completion.lua diff --git a/nvim/lua/lsp-options.lua b/nvim/lua/lsp-options.lua index 55daf09..979d8ec 100644 --- a/nvim/lua/lsp-options.lua +++ b/nvim/lua/lsp-options.lua @@ -59,7 +59,7 @@ end -- used to enable autocompletion (assign to every lsp server config) -- local capabilities = cmp_nvim_lsp.default_capabilities() -M.capabilities = vim.lsp.protocol.make_client_capabilities() +M.capabilities = require("blink.cmp").get_lsp_capabilities(vim.lsp.protocol.make_client_capabilities()) M.capabilities.textDocument.completion.completionItem.snippetSupport = true return M diff --git a/nvim/lua/plugins/lsp/cmp.lua b/nvim/lua/plugins/lsp/cmp.lua deleted file mode 100755 index 4bf2c85..0000000 --- a/nvim/lua/plugins/lsp/cmp.lua +++ /dev/null @@ -1,130 +0,0 @@ -return { - -- competion - "hrsh7th/nvim-cmp", - event = { "InsertEnter", "LspAttach" }, - dependencies = { - { "hrsh7th/cmp-buffer" }, -- source for text in buffer - { "hrsh7th/cmp-path" }, -- source for file system paths - { "L3MON4D3/LuaSnip" }, -- snippet engine - { "saadparwaiz1/cmp_luasnip" }, -- for autocompletion - { "rafamadriz/friendly-snippets" }, -- useful snippets - { "onsails/lspkind.nvim" }, -- icons for cmp - }, - config = function() - local cmp = require("cmp") - local lspkind = require("lspkind") - local luasnip = require("luasnip") - - -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_vscode").load({ paths = { "~/.config/nvim/snippets" } }) - luasnip.setup({}) - - -- luasnip.filetype_extend("htmldjango", { "html" }) - - cmp.setup({ - completion = { - completeopt = "menu,menuone,preview,noselect", - }, - - window = { - documentation = cmp.config.window.bordered({ - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - }), - completion = cmp.config.window.bordered({ - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", - }), - }, - - snippet = { -- configure how nvim-cmp interacts with snippet engine - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.select_next_item({ behavior = cmp.ConfirmBehavior.Select }), -- next suggestion - [""] = cmp.mapping.select_prev_item({ behavior = cmp.ConfirmBehavior.Select }), -- prev suggestion - [""] = cmp.mapping.scroll_docs(4, { behavior = cmp.ConfirmBehavior.Select }), -- docs forward - [""] = cmp.mapping.scroll_docs(-4, { behavior = cmp.ConfirmBehavior.Select }), -- docs back - [""] = cmp.mapping.complete(), -- show completion suggestions - [""] = cmp.mapping.abort(), -- close completion window - [""] = cmp.mapping.confirm({ select = false }), -- autocomplete if selected - -- Mapping for Tab key - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }) - else - -- Otherwise, fallback (insert a tab character) - fallback() - end - end, { "i", "s" }), - - -- Mapping for jumping in snippets - [""] = cmp.mapping(function(fallback) - if require("luasnip").jumpable() then - -- Jump backwards if inside a snippet - require("luasnip").jump() - else - -- Otherwise, fallback (insert a tab character) - fallback() - end - end, { "i", "s" }), - - -- Mapping for jumping backwards in snippets - [""] = cmp.mapping(function(fallback) - if require("luasnip").jumpable() then - -- Jump backwards if inside a snippet - require("luasnip").jump() - else - -- Otherwise, fallback (insert a tab character) - fallback() - end - end, { "i", "s" }), - }), - - -- sources for autocompletion - sources = cmp.config.sources({ - { name = "nvim_lsp" }, -- lsp - { name = "luasnip" }, -- snippets - { name = "buffer" }, -- text within current buffer - { name = "path" }, -- file system paths - }), - - formatting = { - fields = { "icon", "abbr", "menu" }, - format = lspkind.cmp_format({ - mode = "symbol", -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - -- can also be a function to dynamically calculate max width such as - -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end, - ellipsis_char = "…", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) - show_labelDetails = true, -- show labelDetails in menu. Disabled by default - - -- The function below will be called before any actual modifications from lspkind - -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) - before = function(entry, vim_item) - return vim_item - end, - }), - }, - }) - - local opts = { silent = true } - opts.desc = "next snippet placeholder" - vim.keymap.set({ "i", "s" }, "", function() - luasnip.jump(1) - end, opts) - - opts.desc = "previous snippet placeholder" - vim.keymap.set({ "i", "s" }, "", function() - luasnip.jump(-1) - end, opts) - - opts.desc = "LuaSnip unlink" - vim.keymap.set({ "i", "n" }, "", function() - luasnip.unlink_current() - end, opts) - end, -} diff --git a/nvim/lua/plugins/lsp/completion.lua b/nvim/lua/plugins/lsp/completion.lua new file mode 100644 index 0000000..8de9e8a --- /dev/null +++ b/nvim/lua/plugins/lsp/completion.lua @@ -0,0 +1,67 @@ +return { + "saghen/blink.cmp", + -- optional: provides snippets for the snippet source + dependencies = { "rafamadriz/friendly-snippets", "L3MON4D3/LuaSnip" }, + + -- use a release tag to download pre-built binaries + version = "1.*", + + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept) + -- 'super-tab' for mappings similar to vscode (tab to accept) + -- 'enter' for enter to accept + -- 'none' for no mappings + -- + -- All presets have the following mappings: + -- C-space: Open menu or open docs if already open + -- C-n/C-p or Up/Down: Select next/previous item + -- C-e: Hide menu + -- C-k: Toggle signature help (if signature.enabled = true) + -- + -- See :h blink-cmp-config-keymap for defining your own keymap + keymap = { + preset = "super-tab", + [""] = { "select_prev", "fallback" }, + [""] = { "select_next", "fallback" }, + [""] = { "show_documentation", "hide_documentation" }, + [""] = { "scroll_documentation_down", "scroll_signature_down" }, + [""] = { "scroll_documentation_up", "scroll_signature_up" }, + [""] = { "snippet_backward", "fallback" }, + [""] = { "snippet_forward", "fallback" }, + [""] = { "show_signature", "hide_signature", "fallback" }, + }, + + appearance = { + -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = "mono", + }, + + -- (Default) Only show the documentation popup when manually triggered + completion = { + documentation = { auto_show = false }, + list = { + cycle = { from_top = true, from_bottom = true }, + selection = { + auto_insert = false + } + }, + }, + + -- Default list of enabled providers defined so that you can extend it + -- elsewhere in your config, without redefining it, due to `opts_extend` + sources = { + default = { "lsp", "path", "snippets", "buffer" }, + }, + + -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance + -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation, + -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"` + -- + -- See the fuzzy documentation for more information + fuzzy = { implementation = "prefer_rust_with_warning" }, + }, + opts_extend = { "sources.default" }, +} diff --git a/nvim/lua/plugins/lsp/lspconfig.lua b/nvim/lua/plugins/lsp/lspconfig.lua index 9cb8323..c2f2c55 100755 --- a/nvim/lua/plugins/lsp/lspconfig.lua +++ b/nvim/lua/plugins/lsp/lspconfig.lua @@ -3,44 +3,50 @@ -- │ LSP Configuration │ -- ╰───────────────────────────────────────────────╯ return { - -- lsp configuration - "neovim/nvim-lspconfig", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - { "antosha417/nvim-lsp-file-operations", config = true }, - "mfussenegger/nvim-jdtls", - }, - config = function() - -- Change the Diagnostic symbols in the sign column (gutter) - local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶", Info = "󰋽 " } - for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) - end + -- lsp configuration + "neovim/nvim-lspconfig", + dependencies = { + { "antosha417/nvim-lsp-file-operations", config = true }, + "mfussenegger/nvim-jdtls", + }, + config = function() + -- Change the Diagnostic symbols in the sign column (gutter) + local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶", Info = "󰋽 " } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) + end - -- ─────────────────────────────────────────────────────────────────── - -- ╭───────────────────────────────────────────────╮ - -- │ Import configs from other files │ - -- ╰───────────────────────────────────────────────╯ - require("plugins.lsp.ls.bashls") - require("plugins.lsp.ls.c") - require("plugins.lsp.ls.dart") - require("plugins.lsp.ls.docker") - require("plugins.lsp.ls.gh-actions") - require("plugins.lsp.ls.go") - require("plugins.lsp.ls.haskell") - require("plugins.lsp.ls.hypr") - require("plugins.lsp.ls.low-level") - require("plugins.lsp.ls.luals") - require("plugins.lsp.ls.pyright") - require("plugins.lsp.ls.qml") - require("plugins.lsp.ls.rust-analyzer") - require("plugins.lsp.ls.ruby") - require("plugins.lsp.ls.sql") - require("plugins.lsp.ls.text") - require("plugins.lsp.ls.web") - require("plugins.lsp.ls.yaml") - -- ─────────────────────────────────────────────────────────────────── - end, + local luasnip = require("luasnip") + + -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_vscode").load({ paths = { "~/.config/nvim/snippets" } }) + luasnip.setup({}) + + -- ─────────────────────────────────────────────────────────────────── + -- ╭───────────────────────────────────────────────╮ + -- │ Import configs from other files │ + -- ╰───────────────────────────────────────────────╯ + require("plugins.lsp.ls.bashls") + require("plugins.lsp.ls.c") + require("plugins.lsp.ls.dart") + require("plugins.lsp.ls.docker") + require("plugins.lsp.ls.gh-actions") + require("plugins.lsp.ls.go") + require("plugins.lsp.ls.haskell") + require("plugins.lsp.ls.hypr") + require("plugins.lsp.ls.low-level") + require("plugins.lsp.ls.luals") + require("plugins.lsp.ls.pyright") + require("plugins.lsp.ls.qml") + require("plugins.lsp.ls.rust-analyzer") + require("plugins.lsp.ls.ruby") + require("plugins.lsp.ls.sql") + require("plugins.lsp.ls.text") + require("plugins.lsp.ls.web") + require("plugins.lsp.ls.yaml") + -- ─────────────────────────────────────────────────────────────────── + end, } -- ─────────────────────────────────────────────────────────────────── diff --git a/nvim/lua/plugins/style/noice.lua b/nvim/lua/plugins/style/noice.lua index f7b4ad5..f9d6754 100755 --- a/nvim/lua/plugins/style/noice.lua +++ b/nvim/lua/plugins/style/noice.lua @@ -15,11 +15,9 @@ return { }) require("noice").setup({ lsp = { - -- override markdown rendering so that **cmp** and other plugins use **Treesitter** override = { ["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.stylize_markdown"] = true, - ["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp }, progress = { format = "lsp_progress",