Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with nvim-cmp snippet completion #328

Open
mikehaertl opened this issue Nov 12, 2023 · 8 comments
Open

Incompatibility with nvim-cmp snippet completion #328

mikehaertl opened this issue Nov 12, 2023 · 8 comments
Labels

Comments

@mikehaertl
Copy link

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.

  1. Enter insert mode
  2. Type x - it should bring up the completion menu
    image
  3. Move the selection down with <c-j>

The completion menu will close and leave you in this condition:
image

Now comment out the vim-matchup plugin and try the same. This time the menu doesn't close and you can select any item:
image

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: hrsh7th/cmp-vsnip#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
@mikehaertl mikehaertl added the bug label Nov 12, 2023
@andymass
Copy link
Owner

Does cmp offer any mechanism to tell when it is "busy?" Like a function or a variable I can inspect

@mikehaertl
Copy link
Author

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

@andymass
Copy link
Owner

andymass commented Nov 12, 2023

Unfortunately, I can't reproduce the problem with the config given.

One thing you can try is let g:matchup_matchparen_pumvisible = 0.

*g:matchup_matchparen_pumvisible*

@mikehaertl
Copy link
Author

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.

@mikehaertl
Copy link
Author

mikehaertl commented Nov 12, 2023

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.

@3rd
Copy link

3rd commented Nov 16, 2023

👍 Been hitting this issue for a few months, just got around to tracking the problem to vim-matchup.

@andymass
Copy link
Owner

cmp does not use vim's pum instead a custom window. I just pushed a commit that considers cmp.visible as recommended by @mikehaertl

Mythos-404 added a commit to Mythos-404/nvimdots that referenced this issue Jan 16, 2024
@wustho
Copy link

wustho commented Mar 7, 2024

+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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants