vim-matchup
vim-matchup copied to clipboard
Incompatibility with nvim-cmp snippet completion
Explain the issue
When this plugin is enabled I experience an issue with certain vsnippet based snippets in nvim-cmp:
If I move over one of the affected snippets in the nvim-cmp popup menu, the menu immediately closes (without confirmation!). It then leaves me with an incompletely expanded snippet in insert mode.
How to reproduce
Use the config below and start Neovim with nvim -u demo.vim.
- Enter insert mode
- Type
x- it should bring up the completion menu - Move the selection down with
<c-j>
The completion menu will close and leave you in this condition:
Now comment out the vim-matchup plugin and try the same. This time the menu doesn't close and you can select any item:
Additional information
So far I found out that the snippet must meet certain conditions:
- It must include a
textEdit - It probably has to include brackets like
[,{, etc.
Reported here before: https://github.com/hrsh7th/cmp-vsnip/issues/9
Minimal vimrc file
if has('vim_starting')
set encoding=utf-8
endif
scriptencoding utf-8
if &compatible
set nocompatible
endif
let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end
execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/vim-vsnip'
Plug 'andymass/vim-matchup'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<C-j>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i', 'c'}),
['<C-k>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i', 'c'}),
},
sources = cmp.config.sources({
{ name = "demo" },
}),
}
local source = {}
function source:is_available()
return true
end
function source:complete(params, callback)
callback({
{ label = "x1" },
{
label = "x2",
filterText = "x2",
insertTextFormat = cmp.lsp.InsertTextFormat.Snippet,
kind = cmp.lsp.CompletionItemKind.Snippet,
textEdit = {
newText = "[$1]",
range = {
start = {
line = params.context.cursor.line,
-- Hacky way to get correct range - but works for demo
character = params.context.cursor.col - 2,
},
['end'] = {
line = params.context.cursor.line,
character = params.context.cursor.col - 1,
},
},
}
},
{ label = "x3" },
})
end
cmp.register_source('demo', source)
EOF
Does cmp offer any mechanism to tell when it is "busy?" Like a function or a variable I can inspect
Hmm, you can check if the menu is visible, if that helps:
require('cmp').visible()
See https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L155
Unfortunately, I can't reproduce the problem with the config given.
One thing you can try is let g:matchup_matchparen_pumvisible = 0.
https://github.com/andymass/vim-matchup/blob/d30b72d20f01478a8486f15a57c89fe3177373db/doc/matchup.txt#L780
It seems to only happen on the nightly build of neovim: Right now I'm on latest v0.10.0-dev-1535+g9ecb43b63 but also had the problem on an older build based on commit c4f4c7a35 from September.
I've tried with v0.9.3 and don't have the issue there, either.
So not sure if it's worth to investigate. On the other hand if the problem is not adressed it may still be in Neovim v0.10.0 when it's released.
One thing you can try is
let g:matchup_matchparen_pumvisible = 0
Thanks but it does not change the behavior.
If I find time I can bisect the commit that introduced the problem in Neovim.
:+1: Been hitting this issue for a few months, just got around to tracking the problem to vim-matchup.
cmp does not use vim's pum instead a custom window. I just pushed a commit that considers cmp.visible as recommended by @mikehaertl
+1 happens to me as well, thanks for the plugins btw, hopefully this issue will be resolved soon
Altho let g:matchup_matchparen_pumvisible = 0 works when I don't set window configuration to my cmp (ie. use default pumwin)