LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

[Feature Request] Exclude treesitter snippets on extend

Open sharpchen opened this issue 3 months ago • 4 comments

Treesitter snippets are dependent on lang which generally not working on another filetype to extend. So these invalid snippets would be presented unexpectedly on the extended filetype. Maybe we should add special identifier to snippets like treesitter_postfix so that they can be excluded on extend. Or maybe it's more universal to add an identifier for all snippets to indicate whether they can be extended to another filetype.

sharpchen avatar Sep 28 '25 15:09 sharpchen

It sounds like your issue comes from luasnip treating the treesitter languages as the same as the filetypes neovim provides, is that right? Could you maybe give some more specific information on the problem you're facing? Generally, I think issues like this can usually be solved by working with filetype_extends..

L3MON4D3 avatar Sep 29 '25 14:09 L3MON4D3

It sounds like your issue comes from luasnip treating the treesitter languages as the same as the filetypes neovim provides, is that right?

For example, if I have some treesitter_postfix snippets within javascript snippets, and I might extend javascript snippets to typescript. The query might compatible but, lang is fixed so neovim would choose javascript parser to parse typescript file, which eventually make such snippets unusable. Those unusable snippets would still take positions in completion list, that's the problem.

sharpchen avatar Sep 29 '25 15:09 sharpchen

Ahh, I understand.

Excluding snippets from ft_extend sounds like a can of worms, what do you think of setting show_condition on the snippet to check the language of the buffer? It's not possible to expand these snippets manually anyway, so hiding them from completion-menus should be enough to effectively disable them :)

I'd also be fine with just adding this to treesitter_postfix natively, it shouldn't destroy any existing workflow :D

L3MON4D3 avatar Oct 14 '25 13:10 L3MON4D3

I'd like show_condition as it sounds more universal

sharpchen avatar Oct 14 '25 16:10 sharpchen