Optimize file finder subscriptions (#8343)

Fixes #7519 

Optimizes file finder subscriptions — it now only subscribes to
worktrees updates instead of all project updates.

Project panel could also be optimized this way, I guess.

Release Notes:

- Fix selection resets in the file finder during language server
startup ([7519](https://github.com/zed-industries/zed/issues/7519))
This commit is contained in:
Andrew Lygin 2024-02-28 20:02:21 +03:00 committed by GitHub
parent 7aba9eb4b7
commit d0ffd51bb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 155 additions and 11 deletions

View file

@ -365,14 +365,7 @@ impl FileFinderDelegate {
history_items: Vec<FoundPath>,
cx: &mut ViewContext<FileFinder>,
) -> Self {
cx.observe(&project, |file_finder, _, cx| {
//todo We should probably not re-render on every project anything
file_finder
.picker
.update(cx, |picker, cx| picker.refresh(cx))
})
.detach();
Self::subscribe_to_updates(&project, cx);
Self {
file_finder,
workspace,
@ -389,6 +382,20 @@ impl FileFinderDelegate {
}
}
fn subscribe_to_updates(project: &Model<Project>, cx: &mut ViewContext<FileFinder>) {
cx.subscribe(project, |file_finder, _, event, cx| {
match event {
project::Event::WorktreeUpdatedEntries(_, _)
| project::Event::WorktreeAdded
| project::Event::WorktreeRemoved(_) => file_finder
.picker
.update(cx, |picker, cx| picker.refresh(cx)),
_ => {}
};
})
.detach();
}
fn spawn_search(
&mut self,
query: PathLikeWithPosition<FileSearchQuery>,