From 56163b1e3595b98986a2ada8d54df8b72bfc6187 Mon Sep 17 00:00:00 2001 From: Peter Schilling Date: Tue, 15 Oct 2024 12:02:18 -0700 Subject: [PATCH] Add ability to reload a file (#18395) Closes #13212 Release Notes: - Added reload command - vim: Added `:e[dit]`, `:e[dit]!` which calls reload --- crates/editor/src/actions.rs | 1 + crates/editor/src/editor.rs | 12 ++++++++++-- crates/editor/src/element.rs | 3 ++- crates/vim/src/command.rs | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index 502b70361b4f8e0a53c79b8495b1fdb4cb8241d1..b0c7877979f39b64b77dd6fbabc3d6f0326c7e11 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -294,6 +294,7 @@ gpui::actions!( RevealInFileManager, ReverseLines, RevertFile, + ReloadFile, RevertSelectedHunks, Rewrap, ScrollCursorBottom, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 453c012e4d7cfdc5615b5cff3bf23a7ae5d9d3c9..d07002040c555d10bd19707e7b4ae5c923004d38 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -161,11 +161,11 @@ use ui::{ }; use util::{defer, maybe, post_inc, RangeExt, ResultExt, TryFutureExt}; use workspace::item::{ItemHandle, PreviewTabsSettings}; -use workspace::notifications::{DetachAndPromptErr, NotificationId}; +use workspace::notifications::{DetachAndPromptErr, NotificationId, NotifyTaskExt}; use workspace::{ searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId, }; -use workspace::{OpenInTerminal, OpenTerminal, TabBarSettings, Toast}; +use workspace::{Item as WorkspaceItem, OpenInTerminal, OpenTerminal, TabBarSettings, Toast}; use crate::hover_links::find_url; use crate::signature_help::{SignatureHelpHiddenBy, SignatureHelpState}; @@ -6241,6 +6241,13 @@ impl Editor { } } + pub fn reload_file(&mut self, _: &ReloadFile, cx: &mut ViewContext) { + let Some(project) = self.project.clone() else { + return; + }; + self.reload(project, cx).detach_and_notify_err(cx); + } + pub fn revert_selected_hunks(&mut self, _: &RevertSelectedHunks, cx: &mut ViewContext) { let revert_changes = self.gather_revert_changes(&self.selections.disjoint_anchors(), cx); if !revert_changes.is_empty() { @@ -13624,6 +13631,7 @@ pub enum EditorEvent { TransactionBegun { transaction_id: clock::Lamport, }, + Reloaded, CursorShapeChanged, } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 8a2ec5cd0d527286d1fdd1065a988bb82ca769bb..49bb9d7b92508700e63bbedd491d45f1586bd728 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -437,7 +437,8 @@ impl EditorElement { register_action(view, cx, Editor::revert_file); register_action(view, cx, Editor::revert_selected_hunks); register_action(view, cx, Editor::apply_selected_diff_hunks); - register_action(view, cx, Editor::open_active_item_in_terminal) + register_action(view, cx, Editor::open_active_item_in_terminal); + register_action(view, cx, Editor::reload_file) } fn register_key_listeners(&self, cx: &mut WindowContext, layout: &EditorLayout) { diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index 605bc3a05e43c84e00bfb37a0606c4f7180b1289..47975f4cfd0c3111aab3a8d1c8ac071a1eb5bdb6 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -685,6 +685,8 @@ fn generate_commands(_: &AppContext) -> Vec { VimCommand::new(("$", ""), EndOfDocument), VimCommand::new(("%", ""), EndOfDocument), VimCommand::new(("0", ""), StartOfDocument), + VimCommand::new(("e", "dit"), editor::actions::ReloadFile) + .bang(editor::actions::ReloadFile), ] }