mtrajano / tssorter.nvim

Sort almost anything in neovim using treesitter
MIT License
47 stars 0 forks source link

Option to include adjacent nodes when sorting #5

Open sid-6581 opened 1 month ago

sid-6581 commented 1 month ago

My main use case for sorting is things like functions. The problem with that is everything isn't usually nested neatly under a single node, things like comments and attributes can be at the same level as the function declaration. Here is an example in rust:

image

As you can see from this tree, the function node is preceded by the comment and attribute nodes:

image

What I'd love to be able to do is sort all function_item nodes at the same level by name, and include any preceding nodes that belong with the function.

mtrajano commented 1 month ago

This is a very interesting idea and I think something that can be useful for people. I'll look into adding this and comment here with the pr for you to look at. Any ideas for the config key for it? Something like sibling_nodes or anchor_nodes that will take a list of possible nodes that should move with it?

sid-6581 commented 1 month ago

Great, thanks! Maybe include_sibling_nodes could work? I think with a name like that it would be pretty self-descriptive.