LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Show a snippet only at "the top level"

Open MariaSolOs opened this issue 1 year ago • 3 comments

Hello! Not a bug but more of a question :)

I'm struggling to make a snippet show up in completions only when at the top level of a file (so in an empty line). I've tried using the line parameter of show_condition, but that includes the trigger text.

How can I achieve this functionality?

main| // <- Show snippet triggered by main

int foo() {
  main| // Don't show it here
}

MariaSolOs avatar Aug 18 '24 03:08 MariaSolOs

Hi :) Ah, using show_condition you'll have to manually remove the trigger-text (which may be trivial or not, depending on the trigEngine).

Maybe we should pass the snippet itself to show_condition then one could manually call snippet:matches(line_to_cursor) and get the complete trigger-region luasnip would use

L3MON4D3 avatar Aug 20 '24 06:08 L3MON4D3

Maybe we should pass the snippet itself to show_condition then one could manually call snippet:matches(line_to_cursor) and get the complete trigger-region luasnip would use

That sounds like a good idea! It might break some people's configs though, so we should notify them of the breaking change.

MariaSolOs avatar Aug 20 '24 17:08 MariaSolOs

Oh, I would've passed it after the current line_to_cursor, there shouldn't be any breakage. One small issue with changing what is passed to show_condition is that we aren't actually call it, that's the responsibility of eg. cmp_luasnip, so all of those plugins have to make a small change

L3MON4D3 avatar Aug 21 '24 09:08 L3MON4D3