Feature - swap class, function (depending on cursor position)
JoseConseco opened this issue · 6 comments
It would be great if we could swap functions, classes too (depending on where cursor is) . Not sure how much work it would be.
BTW. love the UI for this. Reminds me of https://github.com/mfussenegger/nvim-treehopper which is my fav plug for treesitter nodes selections/management.
I think, the algorithm for the function / class swap (maybe even any node swap) would go something like:
ts_node = nvim_get_node_under_cursor()
If ts_node.type = Function, ( not sure if ts node contain info about its type - is it class_definition or function_definition type?)
get parent = ts_node.parent
children = parent.children
run ISwap on children nodes (that are type of - function or class)
If node does not have info about its type (func, class, conditinal, etc). Then maybe ISwap could do something like this dev:
https://youtu.be/dPQfsASHNkg?t=484 where script gets current line top most parent node, and then run ISwap for sibling of that node.
If we are inside table or tuple then run ISwap old way, and if we are outside then run ISwap on current line code block -this way u could swap any code block that is in current line - not just function, classes. For example pink block (where cursor is) could be swapped with any red ones (siblings)
It would be impossible to target baz. Unless more complicated way would be developed - where instead of picking current line whole block, user would first pick node level that he want to swap, then run iSwap on siblings). First step would be very similar to https://github.com/mfussenegger/nvim-treehopper - where it highlights all parent nodes on which you want to run operation.
About second - I'm not sure what is the issue - you just swap class_definition with its siblings (any red node):
Unless there are no siblings. And possibly ignore siblings that are outside of view...
I may not understand what the issues are with TS, since I did not made any plugins with it.
Closed!