Unnamed repository; edit this file 'description' to name the repository.
automatically reload git repo when commit changes
| -rw-r--r-- | helix-term/src/handlers/auto_reload.rs | 13 | ||||
| -rw-r--r-- | helix-vcs/Cargo.toml | 1 | ||||
| -rw-r--r-- | helix-vcs/src/lib.rs | 14 | ||||
| -rw-r--r-- | helix-view/src/document.rs | 2 |
4 files changed, 29 insertions, 1 deletions
diff --git a/helix-term/src/handlers/auto_reload.rs b/helix-term/src/handlers/auto_reload.rs index df1b28f6..34080bce 100644 --- a/helix-term/src/handlers/auto_reload.rs +++ b/helix-term/src/handlers/auto_reload.rs @@ -36,10 +36,12 @@ impl AutoReload { } job::dispatch_blocking(move |editor, _| { let config = editor.config(); + let mut vcs_reload = false; for fs_event in &*fs_events { if fs_event.ty != EventType::Modified { continue; } + vcs_reload |= editor.diff_providers.needs_reload(fs_event); let Some(doc_id) = editor.document_id_by_path(fs_event.path.as_std_path()) else { return; }; @@ -81,6 +83,17 @@ impl AutoReload { } } } + if vcs_reload { + for doc in editor.documents.values_mut() { + let Some(path) = doc.path() else { + continue; + }; + match editor.diff_providers.get_diff_base(path) { + Some(diff_base) => doc.set_diff_base(diff_base), + None => doc.diff_handle = None, + } + } + } }); } } diff --git a/helix-vcs/Cargo.toml b/helix-vcs/Cargo.toml index e51222a2..d27dd240 100644 --- a/helix-vcs/Cargo.toml +++ b/helix-vcs/Cargo.toml @@ -12,6 +12,7 @@ homepage.workspace = true [dependencies] helix-core = { path = "../helix-core" } helix-event = { path = "../helix-event" } +helix-stdx = { path = "../helix-stdx" } tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] } parking_lot.workspace = true diff --git a/helix-vcs/src/lib.rs b/helix-vcs/src/lib.rs index 4c5f2036..e38cba6f 100644 --- a/helix-vcs/src/lib.rs +++ b/helix-vcs/src/lib.rs @@ -57,6 +57,12 @@ impl DiffProviderRegistry { }) } + pub fn needs_reload(&self, fs_event: &helix_core::file_watcher::Event) -> bool { + self.providers + .iter() + .any(|provider| provider.needs_reload(fs_event)) + } + /// Fire-and-forget changed file iteration. Runs everything in a background task. Keeps /// iteration until `on_change` returns `false`. pub fn for_each_changed_file( @@ -102,6 +108,14 @@ enum DiffProvider { } impl DiffProvider { + pub fn needs_reload(&self, fs_event: &helix_core::file_watcher::Event) -> bool { + match self { + #[cfg(feature = "git")] + DiffProvider::Git => fs_event.path.as_std_path().ends_with(".git/HEAD"), + DiffProvider::None => false, + } + } + fn get_diff_base(&self, file: &Path) -> Result<Vec<u8>> { match self { #[cfg(feature = "git")] diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index b0044d26..ec20bb75 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -196,7 +196,7 @@ pub struct Document { pub(crate) diagnostics: Vec<Diagnostic>, pub(crate) language_servers: HashMap<LanguageServerName, Arc<Client>>, - diff_handle: Option<DiffHandle>, + pub diff_handle: Option<DiffHandle>, version_control_head: Option<Arc<ArcSwap<Box<str>>>>, // when document was used for most-recent-used buffer picker |