Skip to content

Commit 8d0ce7a

Browse files
committed
Revert "feat: switch nvim-cmp for blink.cmp (nvim-lua#1426)"
This reverts commit d350db2. blink.comp doesn't work for me.
1 parent b2f7315 commit 8d0ce7a

File tree

2 files changed

+101
-73
lines changed

2 files changed

+101
-73
lines changed

init.lua

Lines changed: 92 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ require('lazy').setup({
495495
-- Useful status updates for LSP.
496496
{ 'j-hui/fidget.nvim', opts = {} },
497497

498-
-- Allows extra capabilities provided by blink.cmp
499-
'saghen/blink.cmp',
498+
-- Allows extra capabilities provided by nvim-cmp
499+
'hrsh7th/cmp-nvim-lsp',
500500
},
501501
config = function()
502502
-- Brief aside: **What is LSP?**
@@ -663,9 +663,10 @@ require('lazy').setup({
663663

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

670671
-- Enable the following language servers
671672
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
@@ -798,14 +799,12 @@ require('lazy').setup({
798799
},
799800

800801
{ -- Autocompletion
801-
'saghen/blink.cmp',
802-
event = 'VimEnter',
803-
version = '1.*',
802+
'hrsh7th/nvim-cmp',
803+
event = 'InsertEnter',
804804
dependencies = {
805-
-- Snippet Engine
805+
-- Snippet Engine & its associated nvim-cmp source
806806
{
807807
'L3MON4D3/LuaSnip',
808-
version = '2.*',
809808
build = (function()
810809
-- Build Step is needed for regex support in snippets.
811810
-- This step is not supported in many windows environments.
@@ -826,74 +825,95 @@ require('lazy').setup({
826825
-- end,
827826
-- },
828827
},
829-
opts = {},
830828
},
831-
'folke/lazydev.nvim',
829+
'saadparwaiz1/cmp_luasnip',
830+
831+
-- Adds other completion capabilities.
832+
-- nvim-cmp does not ship with all sources by default. They are split
833+
-- into multiple repos for maintenance purposes.
834+
'hrsh7th/cmp-nvim-lsp',
835+
'hrsh7th/cmp-path',
836+
'hrsh7th/cmp-nvim-lsp-signature-help',
832837
},
833-
--- @module 'blink.cmp'
834-
--- @type blink.cmp.Config
835-
opts = {
836-
keymap = {
837-
-- 'default' (recommended) for mappings similar to built-in completions
838-
-- <c-y> to accept ([y]es) the completion.
839-
-- This will auto-import if your LSP supports it.
840-
-- This will expand snippets if the LSP sent a snippet.
841-
-- 'super-tab' for tab to accept
842-
-- 'enter' for enter to accept
843-
-- 'none' for no mappings
844-
--
845-
-- For an understanding of why the 'default' preset is recommended,
846-
-- you will need to read `:help ins-completion`
838+
config = function()
839+
-- See `:help cmp`
840+
local cmp = require 'cmp'
841+
local luasnip = require 'luasnip'
842+
luasnip.config.setup {}
843+
844+
cmp.setup {
845+
snippet = {
846+
expand = function(args)
847+
luasnip.lsp_expand(args.body)
848+
end,
849+
},
850+
completion = { completeopt = 'menu,menuone,noinsert' },
851+
852+
-- For an understanding of why these mappings were
853+
-- chosen, you will need to read `:help ins-completion`
847854
--
848855
-- No, but seriously. Please read `:help ins-completion`, it is really good!
849-
--
850-
-- All presets have the following mappings:
851-
-- <tab>/<s-tab>: move to right/left of your snippet expansion
852-
-- <c-space>: Open menu or open docs if already open
853-
-- <c-n>/<c-p> or <up>/<down>: Select next/previous item
854-
-- <c-e>: Hide menu
855-
-- <c-k>: Toggle signature help
856-
--
857-
-- See :h blink-cmp-config-keymap for defining your own keymap
858-
preset = 'default',
859-
860-
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
861-
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
862-
},
863-
864-
appearance = {
865-
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
866-
-- Adjusts spacing to ensure icons are aligned
867-
nerd_font_variant = 'mono',
868-
},
869-
870-
completion = {
871-
-- By default, you may press `<c-space>` to show the documentation.
872-
-- Optionally, set `auto_show = true` to show the documentation after a delay.
873-
documentation = { auto_show = false, auto_show_delay_ms = 500 },
874-
},
856+
mapping = cmp.mapping.preset.insert {
857+
-- Select the [n]ext item
858+
['<C-n>'] = cmp.mapping.select_next_item(),
859+
-- Select the [p]revious item
860+
['<C-p>'] = cmp.mapping.select_prev_item(),
861+
862+
-- Scroll the documentation window [b]ack / [f]orward
863+
['<C-b>'] = cmp.mapping.scroll_docs(-4),
864+
['<C-f>'] = cmp.mapping.scroll_docs(4),
865+
866+
-- Accept ([y]es) the completion.
867+
-- This will auto-import if your LSP supports it.
868+
-- This will expand snippets if the LSP sent a snippet.
869+
['<C-y>'] = cmp.mapping.confirm { select = true },
870+
871+
-- If you prefer more traditional completion keymaps,
872+
-- you can uncomment the following lines
873+
--['<CR>'] = cmp.mapping.confirm { select = true },
874+
--['<Tab>'] = cmp.mapping.select_next_item(),
875+
--['<S-Tab>'] = cmp.mapping.select_prev_item(),
876+
877+
-- Manually trigger a completion from nvim-cmp.
878+
-- Generally you don't need this, because nvim-cmp will display
879+
-- completions whenever it has completion options available.
880+
['<C-Space>'] = cmp.mapping.complete {},
881+
882+
-- Think of <c-l> as moving to the right of your snippet expansion.
883+
-- So if you have a snippet that's like:
884+
-- function $name($args)
885+
-- $body
886+
-- end
887+
--
888+
-- <c-l> will move you to the right of each of the expansion locations.
889+
-- <c-h> is similar, except moving you backwards.
890+
['<C-l>'] = cmp.mapping(function()
891+
if luasnip.expand_or_locally_jumpable() then
892+
luasnip.expand_or_jump()
893+
end
894+
end, { 'i', 's' }),
895+
['<C-h>'] = cmp.mapping(function()
896+
if luasnip.locally_jumpable(-1) then
897+
luasnip.jump(-1)
898+
end
899+
end, { 'i', 's' }),
875900

876-
sources = {
877-
default = { 'lsp', 'path', 'snippets', 'lazydev' },
878-
providers = {
879-
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
901+
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
902+
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
880903
},
881-
},
882-
883-
snippets = { preset = 'luasnip' },
884-
885-
-- Blink.cmp includes an optional, recommended rust fuzzy matcher,
886-
-- which automatically downloads a prebuilt binary when enabled.
887-
--
888-
-- By default, we use the Lua implementation instead, but you may enable
889-
-- the rust implementation via `'prefer_rust_with_warning'`
890-
--
891-
-- See :h blink-cmp-config-fuzzy for more information
892-
fuzzy = { implementation = 'lua' },
893-
894-
-- Shows a signature help window while you type arguments for a function
895-
signature = { enabled = true },
896-
},
904+
sources = {
905+
{
906+
name = 'lazydev',
907+
-- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
908+
group_index = 0,
909+
},
910+
{ name = 'nvim_lsp' },
911+
{ name = 'luasnip' },
912+
{ name = 'path' },
913+
{ name = 'nvim_lsp_signature_help' },
914+
},
915+
}
916+
end,
897917
},
898918

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

lua/kickstart/plugins/autopairs.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@
44
return {
55
'windwp/nvim-autopairs',
66
event = 'InsertEnter',
7-
opts = {},
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,
816
}

0 commit comments

Comments
 (0)