Can a treesitter_prefix snippet be implemented with luasnip?
Currently there exists a treesitter_postfix snippet which works really well. But is there a way to also have a tresitter_prefix snippet? That would be really helpful to generate javadoc comments, e.g. when I have this method cursor marked with _:
_
public int sum(int x, int y) {
return x + y;
}
and I type some trigger, I would like to get something like this
/**
* <p>$1</p>
* @param x $2
* @param y $3
* @return $4
*/
public int sum(int x, int y) {
return x + y;
}
So basically I want to filter the arguments of the method using tresitter, but not the node before the cursor but after. But because there is no tresitter_prefix snippet I'm not sure how I could implement that.
you can traverse the tree and write query on your own, then return a snippet node by context within dynamic node. tresitter_posfix is just a wrapper around vim.treesitter utilities
Yep, that's how I eventually implemented it too. Maybe when I find the time I can try to create a PR that adds treesitter_prefix, but my current implementation is pretty specific to my problem and not as general as treesitter_postfix.
I think the framework we have for treesitter_postfix is pretty flexible, adding support to optionally look for matches behind instead of before the typed trigger should be possible. One problem is that it was written without considering that the match could also be behind the trigger, so there probably are a few places where one has to pay close attention to not mess up 😅 But definitely a nice idea :+1: (even though for this specific usecase, there exists https://github.com/danymat/neogen)