Skip to content

Commit

Permalink
assistant2: Use notify_async_err for error notifications (#23330)
Browse files Browse the repository at this point in the history
Release Notes:

- N/A
  • Loading branch information
mgsloan authored Jan 18, 2025
1 parent 0199eca commit 8c09a3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 74 deletions.
23 changes: 3 additions & 20 deletions crates/assistant2/src/context_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
27 changes: 7 additions & 20 deletions crates/assistant2/src/context_picker/directory_context_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
27 changes: 7 additions & 20 deletions crates/assistant2/src/context_picker/file_context_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 4 additions & 14 deletions crates/assistant2/src/context_strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
})
Expand Down

0 comments on commit 8c09a3d

Please sign in to comment.