Skip to content

refactor(snippet): rework luasnip source#2238

Draft
soifou wants to merge 13 commits intomainfrom
refactor/luasnip-source
Draft

refactor(snippet): rework luasnip source#2238
soifou wants to merge 13 commits intomainfrom
refactor/luasnip-source

Conversation

@soifou
Copy link
Collaborator

@soifou soifou commented Nov 1, 2025

Some refactoring on this source for easier maintenance with better annotations.

  • A potential fix for Duplicate snippets with Luasnip preset #1081. Possibly a race condition causing duplicated snippets due to premature cache initialization. I haven't been able to reproduce it myself, so if anyone wants to test it out, that'd be great!

  • The insertText is "improved" to be more like other snippet engines or LSPs. For example, for a while~ snippet, it shows whi|le true do instead of the actual whi|le, with support of multi-line snippets, etc., (fallback to the label/trigger). I think it'd align better with what we observe elsewhere.

  • Deprecation of opts.prefer_doc_trig (default true, to be removed in v2) since it has proven very useful and reliable over the months since its introduction.

  • Show blink.cmp completion window for choices as for now we don't have any.

TODO:

@soifou soifou force-pushed the refactor/luasnip-source branch from 8539836 to 2ed5d8e Compare November 11, 2025 22:54
blink.cmp v1.0.0 has been release 8 months ago, this check can be
safely removed now.
Instead of displaying only `trigger`, first try to generate the
preview from the snippet's textNodes; if that's not available, fall
back to `docTrig` if it exists, or use the `trigger` as a last resort.
This setting, which prefers `docTrig` over the trigger, is confusing and
has seen little adoption despite its usefulness.

Users can still opt out in v1.0, but the option will be removed in v2.0
to simplify the codebase.
Update lua annotations using refactor branch
Fix `docTrig` replacement using Luasnip v2.4.1
Add initial support for choice nodes
@soifou soifou force-pushed the refactor/luasnip-source branch from 2ed5d8e to a280624 Compare November 11, 2025 23:00
@saghen
Copy link
Owner

saghen commented Mar 10, 2026

This looks great, any blockers for merging this?

@soifou
Copy link
Collaborator Author

soifou commented Mar 11, 2026

Yep, this only works on the latest LuaSnip main branch (few things break on stable) and we're currently pinned to stable v2.*:

-- `main` is untested, please open a PR if you've confirmed it works as expected
dependencies = { 'L3MON4D3/LuaSnip', version = 'v2.*' },

We could either wait for the next stable LuaSnip release or remove the version pin from docs but this would breaks user configs, so not recommended.

I can backport the few ChoiceNode methods to be compatible with stable v2.* if you prefer to keep this PR moving. Just let me know!

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

Successfully merging this pull request may close these issues.

2 participants