From 47379677f25750c96cbb124180c5c4e283dc4819 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 19 Apr 2022 13:10:36 -0700 Subject: [PATCH 1/2] Update file finder correctly when project files change --- crates/file_finder/src/file_finder.rs | 6 +++--- crates/picker/src/picker.rs | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 9877cef3d80e8d4fa47fb1ddbbf4059ef1e93b46..b43319345647dfd506b78583a9715d99a4a20099 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -129,7 +129,7 @@ impl FileFinder { } fn project_updated(&mut self, _: ModelHandle, cx: &mut ViewContext) { - self.spawn_search(self.latest_search_query.clone(), cx) + self.spawn_search(self.picker.read(cx).query(cx), cx) .detach(); } @@ -379,7 +379,7 @@ mod tests { // Simulate a search being cancelled after the time limit, // returning only a subset of the matches that would have been found. - finder.spawn_search(query.clone(), cx).detach(); + drop(finder.spawn_search(query.clone(), cx)); finder.set_matches( finder.latest_search_id, true, // did-cancel @@ -389,7 +389,7 @@ mod tests { ); // Simulate another cancellation. - finder.spawn_search(query.clone(), cx).detach(); + drop(finder.spawn_search(query.clone(), cx)); finder.set_matches( finder.latest_search_id, true, // did-cancel diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index f23467247820bf4117a8f5606dec9a009489fb61..199429b07e6f857a651fc5822f034216551f6c10 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -150,6 +150,10 @@ impl Picker { self } + pub fn query(&self, cx: &AppContext) -> String { + self.query_editor.read(cx).text(cx) + } + fn on_query_editor_event( &mut self, _: ViewHandle, @@ -171,7 +175,7 @@ impl Picker { fn update_matches(&mut self, cx: &mut ViewContext) { if let Some(delegate) = self.delegate.upgrade(cx) { - let query = self.query_editor.read(cx).text(cx); + let query = self.query(cx); let update = delegate.update(cx, |d, cx| d.update_matches(query, cx)); cx.notify(); self.update_task = Some(cx.spawn(|this, mut cx| async move { From 717ebe6a4c17394dbbccfcfbc22817376815888a Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 19 Apr 2022 13:16:57 -0700 Subject: [PATCH 2/2] Don't cancel match updates when picker query changes The file finder often cancels an in-progress match task when the project updates. But it still needs to take the matches that it did find and add them to its results. So we should not cancel the entire task, as this will cause the partial results to be discarded. --- crates/picker/src/picker.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 199429b07e6f857a651fc5822f034216551f6c10..96062dc0e66a10c47781b5588c71dbe4a8b11f7b 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -18,7 +18,6 @@ pub struct Picker { delegate: WeakViewHandle, query_editor: ViewHandle, list_state: UniformListState, - update_task: Option>, max_size: Vector2F, confirmed: bool, } @@ -136,7 +135,6 @@ impl Picker { let this = Self { query_editor, list_state: Default::default(), - update_task: None, delegate, max_size: vec2f(500., 420.), confirmed: false, @@ -178,7 +176,7 @@ impl Picker { let query = self.query(cx); let update = delegate.update(cx, |d, cx| d.update_matches(query, cx)); cx.notify(); - self.update_task = Some(cx.spawn(|this, mut cx| async move { + cx.spawn(|this, mut cx| async move { update.await; this.update(&mut cx, |this, cx| { if let Some(delegate) = this.delegate.upgrade(cx) { @@ -191,10 +189,10 @@ impl Picker { }; this.list_state.scroll_to(target); cx.notify(); - this.update_task.take(); } }); - })); + }) + .detach() } }