Skip to content

Commit 1d39b8e

Browse files
Saghennickgnd
authored andcommitted
feat: switch nvim-cmp for blink.cmp (nvim-lua#1426)
1 parent df8060e commit 1d39b8e

File tree

3 files changed

+92
-118
lines changed

3 files changed

+92
-118
lines changed

init.lua

Lines changed: 78 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ require('lazy').setup({
551551
-- Useful status updates for LSP.
552552
{ 'j-hui/fidget.nvim', opts = {} },
553553

554-
-- Allows extra capabilities provided by nvim-cmp
555-
'hrsh7th/cmp-nvim-lsp',
554+
-- Allows extra capabilities provided by blink.cmp
555+
'saghen/blink.cmp',
556556
},
557557
config = function()
558558
-- Brief aside: **What is LSP?**
@@ -733,10 +733,9 @@ require('lazy').setup({
733733

734734
-- LSP servers and clients are able to communicate to each other what features they support.
735735
-- By default, Neovim doesn't support everything that is in the LSP specification.
736-
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
737-
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
738-
local capabilities = vim.lsp.protocol.make_client_capabilities()
739-
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
736+
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
737+
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
738+
local capabilities = require('blink.cmp').get_lsp_capabilities()
740739

741740
-- Enable the following language servers
742741
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
@@ -860,12 +859,14 @@ require('lazy').setup({
860859
},
861860

862861
{ -- Autocompletion
863-
'hrsh7th/nvim-cmp',
864-
event = 'InsertEnter',
862+
'saghen/blink.cmp',
863+
event = 'VimEnter',
864+
version = '1.*',
865865
dependencies = {
866-
-- Snippet Engine & its associated nvim-cmp source
866+
-- Snippet Engine
867867
{
868868
'L3MON4D3/LuaSnip',
869+
version = '2.*',
869870
build = (function()
870871
-- Build Step is needed for regex support in snippets.
871872
-- This step is not supported in many windows environments.
@@ -892,96 +893,81 @@ require('lazy').setup({
892893
end,
893894
},
894895
},
896+
opts = {},
895897
},
896-
'saadparwaiz1/cmp_luasnip',
897-
898-
-- Adds other completion capabilities.
899-
-- nvim-cmp does not ship with all sources by default. They are split
900-
-- into multiple repos for maintenance purposes.
901-
'hrsh7th/cmp-nvim-lsp',
902-
'hrsh7th/cmp-path',
903-
'hrsh7th/cmp-nvim-lsp-signature-help',
898+
'folke/lazydev.nvim',
899+
'fang2hou/blink-copilot',
904900
},
905-
config = function()
906-
-- See `:help cmp`
907-
local cmp = require 'cmp'
908-
local luasnip = require 'luasnip'
909-
luasnip.config.setup {}
910-
911-
cmp.setup {
912-
snippet = {
913-
expand = function(args)
914-
luasnip.lsp_expand(args.body)
915-
end,
916-
},
917-
completion = { completeopt = 'menu,menuone,noinsert,popup,fuzzy' },
918-
919-
-- For an understanding of why these mappings were
920-
-- chosen, you will need to read `:help ins-completion`
901+
--- @module 'blink.cmp'
902+
--- @type blink.cmp.Config
903+
opts = {
904+
keymap = {
905+
-- 'default' (recommended) for mappings similar to built-in completions
906+
-- <c-y> to accept ([y]es) the completion.
907+
-- This will auto-import if your LSP supports it.
908+
-- This will expand snippets if the LSP sent a snippet.
909+
-- 'super-tab' for tab to accept
910+
-- 'enter' for enter to accept
911+
-- 'none' for no mappings
912+
--
913+
-- For an understanding of why the 'default' preset is recommended,
914+
-- you will need to read `:help ins-completion`
921915
--
922916
-- No, but seriously. Please read `:help ins-completion`, it is really good!
923-
mapping = cmp.mapping.preset.insert {
924-
-- Select the [n]ext item
925-
['<C-n>'] = cmp.mapping.select_next_item(),
926-
-- Select the [p]revious item
927-
['<C-p>'] = cmp.mapping.select_prev_item(),
928-
929-
-- Scroll the documentation window [b]ack / [f]orward
930-
['<C-b>'] = cmp.mapping.scroll_docs(-4),
931-
['<C-f>'] = cmp.mapping.scroll_docs(4),
932-
933-
-- Accept ([y]es) the completion.
934-
-- This will auto-import if your LSP supports it.
935-
-- This will expand snippets if the LSP sent a snippet.
936-
['<C-y>'] = cmp.mapping.confirm { select = true },
937-
938-
-- If you prefer more traditional completion keymaps,
939-
-- you can uncomment the following lines
940-
--['<CR>'] = cmp.mapping.confirm { select = true },
941-
--['<Tab>'] = cmp.mapping.select_next_item(),
942-
--['<S-Tab>'] = cmp.mapping.select_prev_item(),
943-
944-
-- Manually trigger a completion from nvim-cmp.
945-
-- Generally you don't need this, because nvim-cmp will display
946-
-- completions whenever it has completion options available.
947-
['<C-Space>'] = cmp.mapping.complete {},
948-
949-
-- Think of <c-l> as moving to the right of your snippet expansion.
950-
-- So if you have a snippet that's like:
951-
-- function $name($args)
952-
-- $body
953-
-- end
954-
--
955-
-- <c-l> will move you to the right of each of the expansion locations.
956-
-- <c-h> is similar, except moving you backwards.
957-
['<C-l>'] = cmp.mapping(function()
958-
if luasnip.expand_or_locally_jumpable() then
959-
luasnip.expand_or_jump()
960-
end
961-
end, { 'i', 's' }),
962-
['<C-h>'] = cmp.mapping(function()
963-
if luasnip.locally_jumpable(-1) then
964-
luasnip.jump(-1)
965-
end
966-
end, { 'i', 's' }),
917+
--
918+
-- All presets have the following mappings:
919+
-- <tab>/<s-tab>: move to right/left of your snippet expansion
920+
-- <c-space>: Open menu or open docs if already open
921+
-- <c-n>/<c-p> or <up>/<down>: Select next/previous item
922+
-- <c-e>: Hide menu
923+
-- <c-k>: Toggle signature help
924+
--
925+
-- See :h blink-cmp-config-keymap for defining your own keymap
926+
preset = 'default',
967927

968-
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
969-
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
970-
},
971-
sources = {
972-
{
973-
name = 'lazydev',
974-
-- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
975-
group_index = 0,
928+
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
929+
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
930+
},
931+
932+
appearance = {
933+
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
934+
-- Adjusts spacing to ensure icons are aligned
935+
nerd_font_variant = 'mono',
936+
},
937+
938+
completion = {
939+
-- By default, you may press `<c-space>` to show the documentation.
940+
-- Optionally, set `auto_show = true` to show the documentation after a delay.
941+
documentation = { auto_show = false, auto_show_delay_ms = 500 },
942+
},
943+
944+
sources = {
945+
default = { 'lsp', 'copilot', 'path', 'snippets', 'lazydev' },
946+
providers = {
947+
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
948+
copilot = {
949+
name = 'copilot',
950+
module = 'blink-copilot',
951+
score_offset = 100,
952+
async = true,
976953
},
977-
{ name = 'copilot' },
978-
{ name = 'nvim_lsp' },
979-
{ name = 'luasnip' },
980-
{ name = 'path' },
981-
{ name = 'nvim_lsp_signature_help' },
982954
},
983-
}
984-
end,
955+
},
956+
957+
snippets = { preset = 'luasnip' },
958+
959+
-- Blink.cmp includes an optional, recommended rust fuzzy matcher,
960+
-- which automatically downloads a prebuilt binary when enabled.
961+
--
962+
-- By default, we use the Lua implementation instead, but you may enable
963+
-- the rust implementation via `'prefer_rust_with_warning'`
964+
--
965+
-- See :h blink-cmp-config-fuzzy for more information
966+
fuzzy = { implementation = 'lua' },
967+
968+
-- Shows a signature help window while you type arguments for a function
969+
signature = { enabled = true },
970+
},
985971
},
986972

987973
{ -- You can easily change to a different colorscheme.

lua/custom/plugins/copilot.lua

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
-- Copilot plugin and transform it into a cmp source
2-
-- https://github.com/zbirenbaum/copilot-cmp
1+
-- Copilot plugin and transform it into a blink.cmp source
2+
-- https://github.com/fang2hou/blink-copilot
33
--
44
return {
5-
'zbirenbaum/copilot-cmp',
5+
'zbirenbaum/copilot.lua',
6+
cmd = 'Copilot',
67
event = 'InsertEnter',
7-
config = function()
8-
require('copilot_cmp').setup()
9-
end,
10-
dependencies = {
11-
'zbirenbaum/copilot.lua',
12-
cmd = 'Copilot',
13-
config = function()
14-
require('copilot').setup {
15-
-- It is recommended to disable copilot.lua's suggestion and panel modules,
16-
-- as they can interfere with completions properly appearing in copilot-cmp.
17-
suggestion = { enabled = false },
18-
panel = { enabled = false },
19-
}
20-
end,
8+
opts = {
9+
-- It is recommended to disable copilot.lua's suggestion and panel modules,
10+
-- as they can interfere with completions properly appearing in copilot-cmp.
11+
suggestion = { enabled = false },
12+
panel = { enabled = false },
13+
filetypes = {
14+
markdown = true,
15+
help = true,
16+
},
2117
},
2218
}

lua/kickstart/plugins/autopairs.lua

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,5 @@
44
return {
55
'windwp/nvim-autopairs',
66
event = 'InsertEnter',
7-
-- Optional dependency
8-
dependencies = { 'hrsh7th/nvim-cmp' },
9-
config = function()
10-
require('nvim-autopairs').setup {}
11-
-- If you want to automatically add `(` after selecting a function or method
12-
local cmp_autopairs = require 'nvim-autopairs.completion.cmp'
13-
local cmp = require 'cmp'
14-
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
15-
end,
7+
opts = {},
168
}

0 commit comments

Comments
 (0)