nvim-neo-tree / neo-tree.nvim

Neovim plugin to manage the file system and other tree like structures.
MIT License
3.82k stars 223 forks source link

FEATURE: Add 'refresh' command to force Neo-tree refresh #1381

Closed linrongbin16 closed 7 months ago

linrongbin16 commented 7 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

Sometimes, neo-tree won't refresh the git status & lsp diagnostics in time. So I have to first type <C-w> to navigate to neo-tree window, then press R key to refresh it, then press <C-w> to navigate back to the buffer I'm editing.

Describe the solution you'd like.

Can we create a refresh command? So I could create a key mapping to invoke Neotree refresh to refresh neo-tree.

Describe alternatives you've considered.

No response

Additional Context

No response

cseickel commented 7 months ago

The problem here is that there can be many neo-tree windows so a singular "refresh" would not know which one to work on. If you are OK with assuming you only have one and that one is a filesystem source, then you can do it with this command:

require("neo-tree.sources.filesystem.commands").refresh(require("neo-tree.sources.manager").get_state("filesystem"))

or as multiple lines:

local state = require("neo-tree.sources.manager").get_state("filesystem")
require("neo-tree.sources.filesystem.commands").refresh(state)

This calls the same command that would be called if you hit R in the neo-tree window.

Then again, you should not have to manually refresh. Diagnostics works off of an autocmd and git status would work off of file watchers if you have set the filesystem.use_libuv_file_watcher config option to true.

linrongbin16 commented 7 months ago

thank you for teaching !

GNRSN commented 4 months ago

Also thankful for this explainer. For my usecase I'm opening lazygit within a neovim floating terminal and I find that the git state in neo-tree doesn't update after closing the terminal.

With this I was able to add a callback to refresh after exiting lazygit.