assistant2: Use notify_async_err for error notifications (#23330)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-18 14:10:22 -07:00 committed by GitHub
parent 0199eca289
commit 8c09a3d5db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 74 deletions

View file

@ -14,7 +14,7 @@ use gpui::{
use project::ProjectPath; use project::ProjectPath;
use thread_context_picker::{render_thread_context_entry, ThreadContextEntry}; use thread_context_picker::{render_thread_context_entry, ThreadContextEntry};
use ui::{prelude::*, ContextMenu, ContextMenuEntry, ContextMenuItem}; use ui::{prelude::*, ContextMenu, ContextMenuEntry, ContextMenuItem};
use workspace::Workspace; use workspace::{notifications::NotifyResultExt, Workspace};
use crate::context::ContextKind; use crate::context::ContextKind;
use crate::context_picker::directory_context_picker::DirectoryContextPicker; use crate::context_picker::directory_context_picker::DirectoryContextPicker;
@ -227,25 +227,8 @@ impl ContextPicker {
context_store.add_file_from_path(project_path.clone(), cx) context_store.add_file_from_path(project_path.clone(), cx)
}); });
let workspace = self.workspace.clone(); cx.spawn(|_, mut cx| async move { task.await.notify_async_err(&mut cx) })
.detach();
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.notify(); cx.notify();
} }

View file

@ -8,7 +8,7 @@ use picker::{Picker, PickerDelegate};
use project::{PathMatchCandidateSet, ProjectPath, WorktreeId}; use project::{PathMatchCandidateSet, ProjectPath, WorktreeId};
use ui::{prelude::*, ListItem}; use ui::{prelude::*, ListItem};
use util::ResultExt as _; use util::ResultExt as _;
use workspace::Workspace; use workspace::{notifications::NotifyResultExt, Workspace};
use crate::context_picker::{ConfirmBehavior, ContextPicker}; use crate::context_picker::{ConfirmBehavior, ContextPicker};
use crate::context_store::ContextStore; use crate::context_store::ContextStore;
@ -193,28 +193,15 @@ impl PickerDelegate for DirectoryContextPickerDelegate {
return; return;
}; };
let workspace = self.workspace.clone();
let confirm_behavior = self.confirm_behavior; let confirm_behavior = self.confirm_behavior;
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
match task.await { match task.await.notify_async_err(&mut cx) {
Ok(()) => { None => anyhow::Ok(()),
this.update(&mut cx, |this, cx| match confirm_behavior { Some(()) => this.update(&mut cx, |this, cx| match confirm_behavior {
ConfirmBehavior::KeepOpen => {} ConfirmBehavior::KeepOpen => {}
ConfirmBehavior::Close => this.delegate.dismissed(cx), 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);
})?;
}
} }
anyhow::Ok(())
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);
} }

View file

@ -11,7 +11,7 @@ use picker::{Picker, PickerDelegate};
use project::{PathMatchCandidateSet, ProjectPath, WorktreeId}; use project::{PathMatchCandidateSet, ProjectPath, WorktreeId};
use ui::{prelude::*, ListItem, Tooltip}; use ui::{prelude::*, ListItem, Tooltip};
use util::ResultExt as _; use util::ResultExt as _;
use workspace::Workspace; use workspace::{notifications::NotifyResultExt, Workspace};
use crate::context_picker::{ConfirmBehavior, ContextPicker}; use crate::context_picker::{ConfirmBehavior, ContextPicker};
use crate::context_store::{ContextStore, FileInclusion}; use crate::context_store::{ContextStore, FileInclusion};
@ -211,28 +211,15 @@ impl PickerDelegate for FileContextPickerDelegate {
return; return;
}; };
let workspace = self.workspace.clone();
let confirm_behavior = self.confirm_behavior; let confirm_behavior = self.confirm_behavior;
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
match task.await { match task.await.notify_async_err(&mut cx) {
Ok(()) => { None => anyhow::Ok(()),
this.update(&mut cx, |this, cx| match confirm_behavior { Some(()) => this.update(&mut cx, |this, cx| match confirm_behavior {
ConfirmBehavior::KeepOpen => {} ConfirmBehavior::KeepOpen => {}
ConfirmBehavior::Close => this.delegate.dismissed(cx), 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);
})?;
}
} }
anyhow::Ok(())
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);
} }

View file

@ -10,7 +10,7 @@ use gpui::{
use itertools::Itertools; use itertools::Itertools;
use language::Buffer; use language::Buffer;
use ui::{prelude::*, KeyBinding, PopoverMenu, PopoverMenuHandle, Tooltip}; use ui::{prelude::*, KeyBinding, PopoverMenu, PopoverMenuHandle, Tooltip};
use workspace::Workspace; use workspace::{notifications::NotifyResultExt, Workspace};
use crate::context::ContextKind; use crate::context::ContextKind;
use crate::context_picker::{ConfirmBehavior, ContextPicker}; use crate::context_picker::{ConfirmBehavior, ContextPicker};
@ -311,24 +311,14 @@ impl ContextStrip {
context_store.accept_suggested_context(&suggested, cx) context_store.accept_suggested_context(&suggested, cx)
}); });
let workspace = self.workspace.clone();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
match task.await { match task.await.notify_async_err(&mut cx) {
Ok(()) => { None => {}
Some(()) => {
if let Some(this) = this.upgrade() { if let Some(this) = this.upgrade() {
this.update(&mut cx, |_, cx| cx.notify())?; 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(()) anyhow::Ok(())
}) })