From b67404323c3498b87a39ab7c8881c38cd2947221 Mon Sep 17 00:00:00 2001 From: Suhun Han Date: Tue, 20 Aug 2024 22:05:59 +0900 Subject: [PATCH] workspace: Improve error handling when dropping a file that cannot be opened into the workspace pane (#15613) This PR can improve the UX when dropping a file that cannot be opened into the workspace pane. Previously, nothing happened without any messages when such error occurred, which could be awkward for users. Additionally the pane was being split even though the file failed to open. Here's a screen recording demonstrating the previous/updated behavior: https://github.com/user-attachments/assets/cfdf3488-9464-4568-b16a-9b87718bd729 Changes: - It now displays an error message if a file cannot be opened. - Updated the logic to first try to open the file. The pane splits only if the file opening process is successful. Release Notes: - Improved error handling when opening files in the workspace pane. An error message will now be displayed if the file cannot be opened. - Fixed an issue where unnecessary pane splitting occurred when a file fails to open. --- crates/workspace/src/pane.rs | 43 +++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index c6d1241a4b..08a85d486c 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -3,6 +3,7 @@ use crate::{ ClosePosition, Item, ItemHandle, ItemSettings, PreviewTabsSettings, TabContentParams, WeakItemHandle, }, + notifications::NotifyResultExt, toolbar::Toolbar, workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings}, CloseWindow, CopyPath, CopyRelativePath, NewFile, NewTerminal, OpenInTerminal, OpenTerminal, @@ -2109,13 +2110,32 @@ impl Pane { .read(cx) .path_for_entry(project_entry_id, cx) { - if let Some(split_direction) = split_direction { - to_pane = workspace.split_pane(to_pane, split_direction, cx); - } - workspace - .open_path(path, Some(to_pane.downgrade()), true, cx) - .detach_and_log_err(cx); - } + let load_path_task = workspace.load_path(path, cx); + cx.spawn(|workspace, mut cx| async move { + if let Some((project_entry_id, build_item)) = + load_path_task.await.notify_async_err(&mut cx) + { + workspace + .update(&mut cx, |workspace, cx| { + if let Some(split_direction) = split_direction { + to_pane = + workspace.split_pane(to_pane, split_direction, cx); + } + to_pane.update(cx, |pane, cx| { + pane.open_item( + project_entry_id, + true, + false, + cx, + build_item, + ) + }) + }) + .log_err(); + } + }) + .detach(); + }; }); }) .log_err(); @@ -2186,7 +2206,14 @@ impl Pane { }) .ok() { - let _opened_items: Vec<_> = open_task.await; + let opened_items: Vec<_> = open_task.await; + _ = workspace.update(&mut cx, |workspace, cx| { + for item in opened_items.into_iter().flatten() { + if let Err(e) = item { + workspace.show_error(&e, cx); + } + } + }); } }) .detach();