Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
assistant2: Use `notify_async_err` for error notifications (#23330)
Michael Sloan8c09a3d5db02
diff --git a/crates/assistant2/src/context_picker.rs b/crates/assistant2/src/context_picker.rsindex 4f8e9fd3064..e7adc61eea1 100644--- a/crates/assistant2/src/context_picker.rs+++ b/crates/assistant2/src/context_picker.rs@@ -14,7 +14,7 @@ use gpui::{use project::ProjectPath;use thread_context_picker::{render_thread_context_entry, ThreadContextEntry};use ui::{prelude::*, ContextMenu, ContextMenuEntry, ContextMenuItem};-use workspace::Workspace;+use workspace::{notifications::NotifyResultExt, Workspace};use crate::context::ContextKind;use crate::context_picker::directory_context_picker::DirectoryContextPicker;@@ -227,25 +227,8 @@ impl ContextPicker {context_store.add_file_from_path(project_path.clone(), cx)});- let workspace = self.workspace.clone();-- cx.spawn(|_, mut cx| async move {- match task.await {- Ok(_) => {- return anyhow::Ok(());- }- Err(err) => {- let Some(workspace) = workspace.upgrade() else {- return anyhow::Ok(());- };-- workspace.update(&mut cx, |workspace, cx| {- workspace.show_error(&err, cx);- })- }- }- })- .detach_and_log_err(cx);+ cx.spawn(|_, mut cx| async move { task.await.notify_async_err(&mut cx) })+ .detach();cx.notify();}diff --git a/crates/assistant2/src/context_picker/directory_context_picker.rs b/crates/assistant2/src/context_picker/directory_context_picker.rsindex fce39fec6d9..bdd191037c6 100644--- a/crates/assistant2/src/context_picker/directory_context_picker.rs+++ b/crates/assistant2/src/context_picker/directory_context_picker.rs@@ -8,7 +8,7 @@ use picker::{Picker, PickerDelegate};use project::{PathMatchCandidateSet, ProjectPath, WorktreeId};use ui::{prelude::*, ListItem};use util::ResultExt as _;-use workspace::Workspace;+use workspace::{notifications::NotifyResultExt, Workspace};use crate::context_picker::{ConfirmBehavior, ContextPicker};use crate::context_store::ContextStore;@@ -193,28 +193,15 @@ impl PickerDelegate for DirectoryContextPickerDelegate {return;};- let workspace = self.workspace.clone();let confirm_behavior = self.confirm_behavior;cx.spawn(|this, mut cx| async move {- match task.await {- Ok(()) => {- this.update(&mut cx, |this, cx| match confirm_behavior {- ConfirmBehavior::KeepOpen => {}- ConfirmBehavior::Close => this.delegate.dismissed(cx),- })?;- }- Err(err) => {- let Some(workspace) = workspace.upgrade() else {- return anyhow::Ok(());- };-- workspace.update(&mut cx, |workspace, cx| {- workspace.show_error(&err, cx);- })?;- }+ match task.await.notify_async_err(&mut cx) {+ None => anyhow::Ok(()),+ Some(()) => this.update(&mut cx, |this, cx| match confirm_behavior {+ ConfirmBehavior::KeepOpen => {}+ ConfirmBehavior::Close => this.delegate.dismissed(cx),+ }),}-- anyhow::Ok(())}).detach_and_log_err(cx);}diff --git a/crates/assistant2/src/context_picker/file_context_picker.rs b/crates/assistant2/src/context_picker/file_context_picker.rsindex 533f793bed0..29cab4936e0 100644--- a/crates/assistant2/src/context_picker/file_context_picker.rs+++ b/crates/assistant2/src/context_picker/file_context_picker.rs@@ -11,7 +11,7 @@ use picker::{Picker, PickerDelegate};use project::{PathMatchCandidateSet, ProjectPath, WorktreeId};use ui::{prelude::*, ListItem, Tooltip};use util::ResultExt as _;-use workspace::Workspace;+use workspace::{notifications::NotifyResultExt, Workspace};use crate::context_picker::{ConfirmBehavior, ContextPicker};use crate::context_store::{ContextStore, FileInclusion};@@ -211,28 +211,15 @@ impl PickerDelegate for FileContextPickerDelegate {return;};- let workspace = self.workspace.clone();let confirm_behavior = self.confirm_behavior;cx.spawn(|this, mut cx| async move {- match task.await {- Ok(()) => {- this.update(&mut cx, |this, cx| match confirm_behavior {- ConfirmBehavior::KeepOpen => {}- ConfirmBehavior::Close => this.delegate.dismissed(cx),- })?;- }- Err(err) => {- let Some(workspace) = workspace.upgrade() else {- return anyhow::Ok(());- };-- workspace.update(&mut cx, |workspace, cx| {- workspace.show_error(&err, cx);- })?;- }+ match task.await.notify_async_err(&mut cx) {+ None => anyhow::Ok(()),+ Some(()) => this.update(&mut cx, |this, cx| match confirm_behavior {+ ConfirmBehavior::KeepOpen => {}+ ConfirmBehavior::Close => this.delegate.dismissed(cx),+ }),}-- anyhow::Ok(())}).detach_and_log_err(cx);}diff --git a/crates/assistant2/src/context_strip.rs b/crates/assistant2/src/context_strip.rsindex 4e0d29f848b..e10be7d5eba 100644--- a/crates/assistant2/src/context_strip.rs+++ b/crates/assistant2/src/context_strip.rs@@ -10,7 +10,7 @@ use gpui::{use itertools::Itertools;use language::Buffer;use ui::{prelude::*, KeyBinding, PopoverMenu, PopoverMenuHandle, Tooltip};-use workspace::Workspace;+use workspace::{notifications::NotifyResultExt, Workspace};use crate::context::ContextKind;use crate::context_picker::{ConfirmBehavior, ContextPicker};@@ -311,24 +311,14 @@ impl ContextStrip {context_store.accept_suggested_context(&suggested, cx)});- let workspace = self.workspace.clone();-cx.spawn(|this, mut cx| async move {- match task.await {- Ok(()) => {+ match task.await.notify_async_err(&mut cx) {+ None => {}+ Some(()) => {if let Some(this) = this.upgrade() {this.update(&mut cx, |_, cx| cx.notify())?;}}- Err(err) => {- let Some(workspace) = workspace.upgrade() else {- return anyhow::Ok(());- };-- workspace.update(&mut cx, |workspace, cx| {- workspace.show_error(&err, cx);- })?;- }}anyhow::Ok(())})