simrat39 / symbols-outline.nvim

A tree like view for symbols in Neovim using the Language Server Protocol. Supports all your favourite languages.
MIT License
1.85k stars 100 forks source link

callback to close never works #182

Open gennaro-tedesco opened 1 year ago

gennaro-tedesco commented 1 year ago

I have noticed that the panel with the symbol outline never closes when the associated buffer (from where the symbol outline was invoked) is wiped or changed or closed entirely; as a result one is left with a window of symbol outline open that is associated to nothing. In particular this is also mentioned in https://github.com/simrat39/symbols-outline.nvim/issues/93.

Having a look at the code it seems that the autocommand to close invokes a condition has_code_win() that never evaluates to true: the variable so.state.code_win is set to 1000 and this condition always returns false.

is my understanding incorrect or when exactly does the outline autoclose?

hedyhli commented 11 months ago

Hi @gennaro-tedesco, it might be a bit late, but I've listed some solutions below.

I have noticed that the panel with the symbol outline never closes when the associated buffer (from where the symbol outline was invoked) is wiped or changed or closed entirely

When the window switches to another buffer (that is also supported) the symbols outline window changes to reflect the outline of the new buffer.

However, for the case of the original window being closed entirely (leaving outline as the only window) is a more complicated issue.

Having a look at the code it seems that [...]

Unfortunately the code you are referring to is closing the preview window (floating window opened when you press K, and the auto close does work); I don't think symbols-outline has the functionality of automatically closing the whole outline window after an event. The auto_close option is for auto-closing after a goto_location is triggered (from pressing return by default).

To solve this problem I think there are several approaches.

It's interesting to note that users of nvim-tree also faced this issue and it was decided not to implement such a feature as documented in this wiki page.

However, we can still open a file in a split when nvim-tree is left to become the only window (hence restoring the window layout), and this is not the case for symbols-outline (nor Treesitter :InspectTree as of writing).

Perhaps we can do something like nvim-tree so that symbols-outline can reopen the code buffer when the user either uses goto_selection/focus_location to select an outline item, to not leave the outline window being broken.

Another approach is to let the user choose when to auto close the outline window, similar to what Aerial.nvim does:

  -- List of enum values that configure when to auto-close the aerial window
  --   unfocus       - close aerial when you leave the original source window
  --   switch_buffer - close aerial when you change buffers in the source window
  --   unsupported   - close aerial when attaching to a buffer that has no symbol source
  close_automatic_events = {},

In the meantime while none of the above is implemented, a workaround is to use plugins like vim-bbye, which will retain your window layout by opening another buffer when you delete this one. (#75)

Another option is to just use :bdelete to close the outline window, then continue editing files and open outline window again when needed.


With all of this aside it seems like simrat39 is not very active at the moment. Maybe you could try out Aerial.nvim if it fits your needs better. If not I am working on my fork and when the solution is implemented I will update in this issue.