folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.45k stars 32 forks source link

feature: add support for jumping/selecting treesitter child and siblings nodes #64

Closed benelan closed 1 year ago

benelan commented 1 year ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

No problem

Describe the solution you'd like

Add support for jumping to or selecting treesitter child or sibling nodes. At the time of writing, only parent nodes are supported.

Describe alternatives you've considered

My current alternative is doing a normal jump into the treesitter node I'm aiming for and using a text object to select it.

Additional context

Thanks for making this plugin, it's great!

Relevant Neovim APIs:

https://github.com/neovim/neovim/blob/cd6458123fb4859e47ffcd144ebbddf389a09610/runtime/lua/vim/treesitter/_meta.lua#L22-L25

A plugin that supports jumping between treesitter sibling nodes for inspiration: https://github.com/ziontee113/syntax-tree-surfer

IndianBoy42 commented 1 year ago

See this PR: https://github.com/folke/flash.nvim/pull/51#issuecomment-1606217091

The PR itself is actually useless but it contains examples for searching and selecting any treesitter node, that should work on master

benelan commented 1 year ago

If you're referring to this comment, it's not quite what I was looking for. The snippet folke provided selects from the current cursor location to the chosen label.

I was looking for the exact same behavior as require("flash").treesitter() (a.k.a selecting the node itself), but including labels for child and sibling nodes too.

If that makes things too cluttered it could be an option like require("flash").treesitter({type = "sibling"}) or something along those lines.

But I may be able to figure it out by tweaking the snippet, thanks for pointing me in the right direction!

IndianBoy42 commented 1 year ago

Try it without remote for the normal and visual modes. It should select the node around the match (there should be double sided labelling just like treesitter)

benelan commented 1 year ago

Closing as the snippet in https://github.com/folke/flash.nvim/pull/51#issuecomment-1607124051 is close enough to what I was looking for. Thanks your hard work on this @folke!

folke commented 1 year ago

That has been integrated in flash in the meantime. Check the docs for treesitter_search