From ae0237c21b02457c1c92e8213b356020c9952d1b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 31 Jan 2022 18:33:25 -0700 Subject: [PATCH] Create anchors with latest snapshot when completions are ready Using the previous snapshot was panicking. --- crates/editor/src/multi_buffer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 11aec10d5c..ccae933517 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -856,13 +856,13 @@ impl MultiBuffer { where T: ToOffset, { - let snapshot = self.snapshot(cx); - let anchor = snapshot.anchor_before(position); + let anchor = self.read(cx).anchor_before(position); let buffer = self.buffers.borrow()[&anchor.buffer_id].buffer.clone(); let completions = buffer.update(cx, |buffer, cx| buffer.completions(anchor.text_anchor, cx)); - cx.foreground().spawn(async move { + cx.spawn(|this, cx| async move { completions.await.map(|completions| { + let snapshot = this.read_with(&cx, |buffer, cx| buffer.snapshot(cx)); completions .into_iter() .map(|completion| Completion {