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

Show a snippet only at "the top level" #1223

Open
MariaSolOs opened this issue Aug 18, 2024 · 3 comments
Open

Show a snippet only at "the top level" #1223

MariaSolOs opened this issue Aug 18, 2024 · 3 comments

Comments

@MariaSolOs
Copy link

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
}
@L3MON4D3
Copy link
Owner

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

@MariaSolOs
Copy link
Author

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.

@L3MON4D3
Copy link
Owner

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

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

No branches or pull requests

2 participants