How to inform neotree source about some external events #1313
Replies: 3 comments 2 replies
-
IIRC you don't have a great way of doing this with neo-tree directly (correct me if I am wrong @cseickel ). You can in theory pull the state of your source with I very briefly dove down that rabbit hole before settling on what we talked about before, managing the state yourself. If you go that route, you don't really care when your changes happen, you just care about when to show them and that is easy enough to do with |
Beta Was this translation helpful? Give feedback.
-
I'm working from memory here, but I'm pretty sure the rest of the sources are effectively paused and do not maintain the state of the tree at all if they are not visible. The only exception is lsp diagnostic info. Those events will continue to come in whenever the diagnostic autocmds fire and the information will just be recorded on the state object. The tree is not directly affected by this though because LSP info is only looked up at render time and is not actually maintained within the tree nodes at all. As an extreme example, the buffers list just calls the nvim api to list all buffers every time it is shown and every time an event fires that may change the list of buffers while it's open. If it's not open then all events are ignored. There's really no source specific state to maintain at all. I think the filesystem source will still process file changed events from the libuv watchers (if enabled) but it won't do anything about it if the source is not visible, it will just mark the tree as stale which will cause it to refresh the next time it is opened. As a general rule, I think it is desirable that any source that is not visible should not active in any way. |
Beta Was this translation helpful? Give feedback.
-
Thank you both for writing these answers, they are very helpful 🙇♂️ |
Beta Was this translation helpful? Give feedback.
-
In my case I have a source that represents data from a language server.
That data comes asynchronously via notification to the client in two cases:
I figured out that I will use the event system as follow:
setup
functionHowever, I am not sure how to update tree state without rendering it, as the rendering code is responsible for creation of
NuiNodes
that I use to keep the state. Rn I use therenderer.show_nodes
method but it has this side-effect that it also shows my source in the neotree.I would like only to update the state without switching the current visible source. Is this possible?
Code below:
external api entrypoint
setup:
You can find the full code here
Beta Was this translation helpful? Give feedback.
All reactions