From ad52bf91bc8f1821bbb0b7218d03768eec9a9e42 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 2 Nov 2024 09:54:55 +0100 Subject: [PATCH] feat(extras): blink (#4680) ## Description Extra to use [blink.cmp](https://github.com/Saghen/blink.cmp) instead of **nvim-cmp**. ## Todo - [x] tokyonight suport - [x] basic integration - [ ] check / update all cmp sources - [ ] copilot and others integration - [x] native lazydev source ## Limitations There's no copilot source, so instead when enabling both blink and copilot: - blink ghost text is disabled - copilot suggestions are enabled - use `` to navigate snippets and accept copilot completions ## Related Issue(s) - https://github.com/LazyVim/LazyVim/discussions/4679 --- lua/lazyvim/plugins/extras/coding/blink.lua | 96 +++++++++++++++++++ lua/lazyvim/plugins/extras/coding/copilot.lua | 40 ++++++++ lua/lazyvim/plugins/lsp/init.lua | 2 + lua/lazyvim/plugins/xtras.lua | 1 + lua/lazyvim/util/cmp.lua | 10 +- 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 lua/lazyvim/plugins/extras/coding/blink.lua diff --git a/lua/lazyvim/plugins/extras/coding/blink.lua b/lua/lazyvim/plugins/extras/coding/blink.lua new file mode 100644 index 00000000..e571fc10 --- /dev/null +++ b/lua/lazyvim/plugins/extras/coding/blink.lua @@ -0,0 +1,96 @@ +return { + { + "hrsh7th/nvim-cmp", + enabled = false, + }, + { + "saghen/blink.cmp", + -- TODO: use release version + -- version = "*", + opts_extend = { "sources.completion.enabled_providers" }, + dependencies = { + "rafamadriz/friendly-snippets", + -- add blink.compat to dependencies + -- { "saghen/blink.compat", opts = {} }, + }, + event = "InsertEnter", + + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + fuzzy = { + prebuilt_binaries = { + download = true, + force_version = "v0.5.0", + }, + }, + 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 = false, + }, + -- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- adjusts spacing to ensure icons are aligned + nerd_font_variant = "mono", + windows = { + autocomplete = { + draw = "reversed", + }, + documentation = { + auto_show = true, + }, + ghost_text = { + enabled = true, + }, + }, + + -- experimental auto-brackets support + accept = { auto_brackets = { enabled = true } }, + + -- experimental signature help support + -- trigger = { signature_help = { enabled = true } } + sources = { + completion = { + -- remember to enable your providers here + enabled_providers = { "lsp", "path", "snippets", "buffer" }, + }, + }, + + keymap = { + preset = "enter", + }, + }, + }, + + -- add icons + { + "saghen/blink.cmp", + opts = function(_, opts) + opts.kind_icons = LazyVim.config.icons.kinds + end, + }, + + -- lazydev + { + "saghen/blink.cmp", + opts = { + sources = { + completion = { + -- add lazydev to your completion providers + enabled_providers = { "lazydev" }, + }, + providers = { + lsp = { + -- dont show LuaLS require statements when lazydev has items + fallback_for = { "lazydev" }, + }, + lazydev = { + name = "LazyDev", + module = "lazydev.integrations.blink", + }, + }, + }, + }, + }, +} diff --git a/lua/lazyvim/plugins/extras/coding/copilot.lua b/lua/lazyvim/plugins/extras/coding/copilot.lua index 8f0680ea..4d737379 100644 --- a/lua/lazyvim/plugins/extras/coding/copilot.lua +++ b/lua/lazyvim/plugins/extras/coding/copilot.lua @@ -80,4 +80,44 @@ return { }) end, }, + + { + "saghen/blink.cmp", + optional = true, + specs = { + { + "zbirenbaum/copilot.lua", + event = "InsertEnter", + opts = { + suggestion = { + enabled = true, + auto_trigger = true, + keymap = { accept = false }, + }, + }, + }, + }, + opts = { + windows = { + ghost_text = { + enabled = false, + }, + }, + keymap = { + [""] = { + function(cmp) + if cmp.is_in_snippet() then + return cmp.accept() + elseif require("copilot.suggestion").is_visible() then + require("copilot.suggestion").accept() + else + return cmp.select_and_accept() + end + end, + "snippet_forward", + "fallback", + }, + }, + }, + }, } diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 076344dd..3e8bc8b7 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -184,11 +184,13 @@ return { local servers = opts.servers local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + local has_blink, blink = pcall(require, "blink.cmp") local capabilities = vim.tbl_deep_extend( "force", {}, vim.lsp.protocol.make_client_capabilities(), has_cmp and cmp_nvim_lsp.default_capabilities() or {}, + has_blink and blink.get_lsp_capabilities() or {}, opts.capabilities or {} ) diff --git a/lua/lazyvim/plugins/xtras.lua b/lua/lazyvim/plugins/xtras.lua index 0527dde5..c2b52cb6 100644 --- a/lua/lazyvim/plugins/xtras.lua +++ b/lua/lazyvim/plugins/xtras.lua @@ -4,6 +4,7 @@ local prios = { ["lazyvim.plugins.extras.dap.core"] = 1, ["lazyvim.plugins.extras.ui.edgy"] = 2, ["lazyvim.plugins.extras.lang.typescript"] = 5, + ["lazyvim.plugins.extras.coding.blink"] = 5, ["lazyvim.plugins.extras.formatting.prettier"] = 10, -- default priority is 50 ["lazyvim.plugins.extras.editor.aerial"] = 100, diff --git a/lua/lazyvim/util/cmp.lua b/lua/lazyvim/util/cmp.lua index 8cb3d1bc..5eff81fa 100644 --- a/lua/lazyvim/util/cmp.lua +++ b/lua/lazyvim/util/cmp.lua @@ -71,9 +71,17 @@ function M.add_missing_snippet_docs(window) end function M.visible() + ---@module 'blink.cmp' + local blink = package.loaded["blink.cmp"] + if blink then + return blink.windows and blink.windows.autocomplete.win:is_open() + end ---@module 'cmp' local cmp = package.loaded["cmp"] - return cmp and cmp.core.view:visible() + if cmp then + return cmp.core.view:visible() + end + return false end -- This is a better implementation of `cmp.confirm`: