dcampos / nvim-snippy

Snippet plugin for Neovim written in Lua
MIT License
309 stars 18 forks source link

When using with cmp, expanding a variable with a reference causes breakage in cmp's menu #116

Open unphased opened 1 year ago

unphased commented 1 year ago

Description

I was testing with my standard console.log snippet:

snippet l
        console.log('${VISUAL}$1:'${2:, ${VISUAL}$1});

When "fancy" snippets like this are being used, interactions are poor with the cmp menu.

Steps to Reproduce

  1. l to type l. the snippet shows in cmp list
  2. <tab> to move cmp selection down to l snippet
  3. <cr> to expand the l snippet. snippy interaction starts here.
  4. ab loads up cmp completion list filled with ab... entries
  5. <tab> move the selection down to the first of the ab... entries

Typically at this point, cmp selection causes the first result to fill into buffer, e.g. abcd. This does happen, and snippy picks it up! Which is great. What happens to cmp's currently-open completion menu, however, isn't great.

Expected Result

Expect cmp's completion list not to be clobbered

Actual Result

cmp's completion list gets clobbered at this point. it was listing the full list of ab... symbols but once the complex snippet expansion happens in response to cmp filling the current tabstop, the completion list now only shows this only one that matches

Additional Context

No response

unphased commented 1 year ago

Alright I wanna say that I solved this 90% satisfactorily via https://github.com/hrsh7th/nvim-cmp/discussions/1685

But I will leave this ticket open for now in order to continue fishing for ideas to make it better. Basically the solution is to detect whenever snippy is still active, and simply cause cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) to be run instead of the default which allows for bypassing the root problem while not making it much worse in experience.

What I like about it is that it lets me keep the default cmp.SelectBehavior.Insert when a snippet context isn't active, which is most of the time.

dcampos commented 1 year ago

The issue only occurred when using cmp's custom completion menu. Mirroring the tabstop seemed to reset the menu.

The solution I found was to check the visibility of the menu (cmp.visible()) and only perform the mirroring if it is not visible. Please let me know if this still does not work for you.

unphased commented 1 year ago

Thanks. As you can see in my follow up comment, I found a way to do pretty much almost exactly what you describe via cmp bind function logic.

I don't think having both would be detrimental but I'll try to mess around with it more when I get a chance. Thanks.

dcampos commented 1 year ago

Calling cmp.visible() seems to cause input lag, so I've reverted my commit until a better solution is found.