Detailed changes
@@ -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();
}
@@ -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);
}
@@ -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);
}
@@ -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(())
})