hrsh7th / cmp-vsnip

nvim-cmp source for vim-vsnip
MIT License
90 stars 4 forks source link

Select prev/next immediately closes menu for some snippets #9

Closed mikehaertl closed 7 months ago

mikehaertl commented 8 months ago

Some snippets cause the menu to immediately close, when selected with prev/next in the menu. They also insert a messed up version of the snippet.

Here is an example snippet:

{
  "msg": {
    "prefix": ["msg"],
    "body": [
      "[$1] $2"
    ]
  }
}

If I type ms the menu opens: image

If I now just select the first item (i.e. <c-j> without confirming!), the menu closes immediately and inserts the first part of the template:

image

This happens since commit 18ff44c (Improve Symbol handling).

It does not happen for all snippets. I could not find out what exactly makes some snippets cause this problems, while others still work fine.

My nvim-cmp config:

  cmp.setup({
    snippet = {
      expand = function(args)
        vim.fn['vsnip#anonymous'](args.body)
      end,
    },
    mapping = {
      ['<C-j>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i', 'c'}),
      ['<C-k>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i', 'c'}),
      ['<CR>'] = function(fallback)
        if cmp.visible() and
          cmp.get_selected_entry() and
          not (cmp.get_selected_entry().source.name == 'nvim_lsp_signature_help') then
          cmp.confirm({
            select = false,
          })
        else
          fallback()
        end
      end
    },
    sources = cmp.config.sources({
      { name = 'vsnip' },
    }),
  })
mikehaertl commented 7 months ago

The issue goes away if I disable the https://github.com/andymass/vim-matchup plugin. So it must probably get fixed there.