Fix excluded file creation (#12620)

Fixes https://github.com/zed-industries/zed/issues/10890

* removes `unwrap()` that caused panics for text elements with no text,
remaining after edit state is cleared but project entries are not
updated, having the fake, "new entry"
* improves discoverability of the FS errors during file/directory
creation: now those are shown as workspace notifications
* stops printing anyhow backtraces in workspace notifications, printing
the more readable chain of contexts instead
* better indicates when new entries are created as excluded ones


Release Notes:

- Improve excluded entry creation workflow in the project panel
([10890](https://github.com/zed-industries/zed/issues/10890))
This commit is contained in:
Kirill Bulatov 2024-06-04 10:31:43 +03:00 committed by GitHub
parent edd613062a
commit 47122a3115
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 447 additions and 58 deletions

View file

@ -122,6 +122,15 @@ impl Workspace {
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn notification_ids(&self) -> Vec<NotificationId> {
self.notifications
.iter()
.map(|(id, _)| id)
.cloned()
.collect()
}
pub fn show_notification<V: Notification>(
&mut self,
id: NotificationId,
@ -144,7 +153,7 @@ impl Workspace {
pub fn show_error<E>(&mut self, err: &E, cx: &mut ViewContext<Self>)
where
E: std::fmt::Debug,
E: std::fmt::Debug + std::fmt::Display,
{
struct WorkspaceErrorNotification;
@ -153,7 +162,7 @@ impl Workspace {
cx,
|cx| {
cx.new_view(|_cx| {
simple_message_notification::MessageNotification::new(format!("Error: {err:?}"))
simple_message_notification::MessageNotification::new(format!("Error: {err:#}"))
})
},
);
@ -464,7 +473,7 @@ pub trait NotifyResultExt {
impl<T, E> NotifyResultExt for Result<T, E>
where
E: std::fmt::Debug,
E: std::fmt::Debug + std::fmt::Display,
{
type Ok = T;
@ -483,7 +492,7 @@ where
match self {
Ok(value) => Some(value),
Err(err) => {
log::error!("TODO {err:?}");
log::error!("{err:?}");
cx.update_root(|view, cx| {
if let Ok(workspace) = view.downcast::<Workspace>() {
workspace.update(cx, |workspace, cx| workspace.show_error(&err, cx))
@ -502,7 +511,7 @@ pub trait NotifyTaskExt {
impl<R, E> NotifyTaskExt for Task<Result<R, E>>
where
E: std::fmt::Debug + Sized + 'static,
E: std::fmt::Debug + std::fmt::Display + Sized + 'static,
R: 'static,
{
fn detach_and_notify_err(self, cx: &mut WindowContext) {