nvim-treehopper icon indicating copy to clipboard operation
nvim-treehopper copied to clipboard

Feature Suggestion: Hints for objects *outside* nodes containing the cursor

Open chrisgrieser opened this issue 2 years ago • 3 comments

I just stumbled upon this plugin and I must say, I find it's concept very intriguing.

Having played around with it for a bit, I noticed that this plugin restricts the hints and therefore actionable area to nodes containing the cursor. When in a big, deeply nested node like in the demo in the readme, that makes sense, but when in areas with a long sequence of non-nested nodes like an array, this makes the plugin rather unuseful: CleanShot 2023-04-01 at 14 56 06

So my idea is to introduce options to change the area actionable (= getting hints) from the plugin:

  • currently, we can action on nodes containing the cursor
  • one option could be nodes not containing the cursor, i.e. inverting the actionable area. This could be interesting, since you can often select things that contain the cursor via other text objects already. However, objects at a distance are far more limited to interact with (apart from the forward-seeking from plugins like targets.vim)
  • or one could simply enable hints for all nodes, or all nodes after/before the cursor?

chrisgrieser avatar Apr 01 '23 13:04 chrisgrieser

all nodes sounds like it would clutter up the screen quite a lot. playing with hop.nvim with some custom lua for using treesitter queries I am finding the screen gets very busy very quickly. you would have to be very careful about which nodes you show hints for.

IndianBoy42 avatar Apr 02 '23 16:04 IndianBoy42

all nodes sounds like it would clutter up the screen quite a lot.

that does depend on your window size, which true, isn't that big for me most of the time. One could also restrict this to x lines below or above the cursor maybe?


Nevertheless, I made this to illustrate my point: treehopper offers me hints to jump inside the current node (red), which isn't all to helpful here sind I can already reach various parts of this node via ii, ia, ac etc pretty easily.

What isn't quickly to reach are locations in neighboring nodes (blue) – but for those, treehopper does not offer hints. CleanShot 2023-04-03 at 13 14 41@2x

chrisgrieser avatar Apr 03 '23 11:04 chrisgrieser

I'm not saying hopping to other nodes other than the immediately containing nodes isn't useful, although it probably is more the responsibility of hop.nvim or an extension of hop.nvim (which treehopper uses for the moving btw). I'm saying if you simply add hints for every single treesitter node there will be so many labels (and most will end up needing 2 key presses that the entire screen is covered in labels. So you need to be smart about how you choose the nodes to add targets. It's not about how many lines up or down (although that affects slightly based on how many targets will require 2 keypresses) but about the density of nodes. Remember the treesitter tree is a very detailed and information dense CST, almost every token is a node, and then those nodes are contained by other nodes, etc. Look at :TSPlayground.

I've been playing around with a hop.nvim extension (you can check out my account) for navigating based on treesitter and it's non obvious which nodes should be hop targets and which shouldn't. Unless selection, the main original point of treehopper, where all containing nodes works well.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: pseudometa @.> Sent: Monday, April 3, 2023 7:18:18 PM To: mfussenegger/nvim-treehopper @.> Cc: Anshuman MEDHI @.>; Comment @.> Subject: Re: [mfussenegger/nvim-treehopper] Feature Suggestion: Hints for objects outside nodes containing the cursor (Issue #33)

all nodes sounds like it would clutter up the screen quite a lot.

that does depend on your window size, which true, isn't that big for me most of the time. One could also restrict this to x lines below or above the cursor maybe?


Nevertheless, I made this to illustrate my point: treehopper offers me hints to jump inside the current node (red), which isn't all to helpful here sind I can already reach various parts of this node via ii, ia, ac etc pretty easily.

What isn't quickly to reach are locations in neighboring nodes (blue) – but for those, treehopper does not offer hints. [CleanShot 2023-04-03 at 13 14 @.***https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F73286100%2F229494021-198d1531-7bc4-4c18-b57e-cedabd449fe4.png&data=05%7C01%7Camedhi%40connect.ust.hk%7C5e4cd815ab794bad75f108db343521b2%7C6c1d415239d044ca88d9b8d6ddca0708%7C1%7C0%7C638161175028526123%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=C2G1x0sAarTrKAbtQAxsoBtgKi%2Bf%2B7XtspPCmSXeyrY%3D&reserved=0

— Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmfussenegger%2Fnvim-treehopper%2Fissues%2F33%23issuecomment-1494138242&data=05%7C01%7Camedhi%40connect.ust.hk%7C5e4cd815ab794bad75f108db343521b2%7C6c1d415239d044ca88d9b8d6ddca0708%7C1%7C0%7C638161175028526123%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=GIYdPpWP667U80DZc1VY7xzaea%2FK%2FfRhnHVUeR2y50M%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABNUNQICHR25OD2Q23YGUCDW7KWXVANCNFSM6AAAAAAWPT6BKU&data=05%7C01%7Camedhi%40connect.ust.hk%7C5e4cd815ab794bad75f108db343521b2%7C6c1d415239d044ca88d9b8d6ddca0708%7C1%7C0%7C638161175028682367%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2Fh%2FOazcEOpsBpO3oF2%2BqOHciDmt6iArZIOuPY0%2B2Dn8%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

IndianBoy42 avatar Apr 03 '23 12:04 IndianBoy42