stevearc / aerial.nvim

Neovim plugin for a code outline window
MIT License
1.72k stars 83 forks source link

Feature request for tree_close_all_except_active() #235

Closed JoseConseco closed 1 year ago

JoseConseco commented 1 year ago

I wanted to auto-close all fold in aerial, when navigating through sibling items, except item under cursor. Right now I use: ["l"] = { callback = function() local current_line_str = vim.api.nvim_get_current_line(); aerial.tree_close_all(); vim.fn.search(current_line_str); aerial.tree_open() end, desc = "", nowait = true }, I have to store and restore cursor position using current_line_str, since aerial.tree_close_all() moves cursor away from active item. The issue I try to solve is - I want to emulate something like in - https://github.com/SmiteshP/nvim-navbuddy - where only content of node under cursor is shown. This way I would not have to use zc, every time when moving to sibling. And while navbuddy is cool - it does not allow filtering of node types (eg. to only show classes, and methods)

stevearc commented 1 year ago

Interesting. I've spent some time thinking about it, and I think that it would be easier to emulate the functionality of nvim-navbuddy than it would be to make the current view behave like you want. The main issue is the 1-to-1 mapping of aerial to code folding. Focusing on the symbol under the cursor will always require a lot of kludgy hacks and jumping around. In comparison, adding that new view is relatively straightforward and just another way to visualize the data that we already have.

I'll start playing around with it, but can't promise any sort of timeline

JoseConseco commented 1 year ago

Thx, no pressure. I actually talked to nav-buddy dev, and he is going to implement filtering option through some handler function, where user will be able to process/discard lsp entries before they are shown. Still I find this way of navigation cool, and may be of use to Aerial users.

stevearc commented 1 year ago

Have a first draft ready to go. Try it out with :AerialNavToggle

JoseConseco commented 1 year ago

Its is even better than I though - with side columns, parent and child nodes are visible without having to navigate into entry. I wonder - if we highlight leaf node - could right empty 'column' show preview the content of node (kind of like Telescope preview)?
image Thanks for implementing this.

JoseConseco commented 1 year ago

Ok , I found one issue - esc or 'q' wont close the AerialNavToggle

stevearc commented 1 year ago

You can map those keys to the close action. I've also added an option to preview the symbol code in the rightmost column if there are no child symbols. You can enable both of those with the following:

require("aerial").setup({
  nav = {
    preview = true,
    keymaps = {
      ["<Esc>"] = "actions.close",
      q = "actions.close",
    },
  },
})
JoseConseco commented 1 year ago

All works great now! Thanks for these improvements, navigation through code is very fluent now.