aboutsummaryrefslogtreecommitdiff
path: root/helix-vcs/src/diff
diff options
context:
space:
mode:
authorPascal Kuthe2023-03-08 01:49:14 +0000
committerGitHub2023-03-08 01:49:14 +0000
commit48b6aa9a699df0680a6d31e9611ebd1ca9909de4 (patch)
tree11459e49578000678f494857cfbe1f60bfe2ba20 /helix-vcs/src/diff
parent8c2e447b16e4d11db411b18f2fbe3ac2bc031d89 (diff)
Add command for resetting diff hunks (#5736)
Diffstat (limited to 'helix-vcs/src/diff')
-rw-r--r--helix-vcs/src/diff/line_cache.rs8
-rw-r--r--helix-vcs/src/diff/worker.rs15
-rw-r--r--helix-vcs/src/diff/worker/test.rs6
3 files changed, 20 insertions, 9 deletions
diff --git a/helix-vcs/src/diff/line_cache.rs b/helix-vcs/src/diff/line_cache.rs
index c3ee5daa..8e48250f 100644
--- a/helix-vcs/src/diff/line_cache.rs
+++ b/helix-vcs/src/diff/line_cache.rs
@@ -43,6 +43,14 @@ impl InternedRopeLines {
res
}
+ pub fn doc(&self) -> Rope {
+ self.doc.clone()
+ }
+
+ pub fn diff_base(&self) -> Rope {
+ self.diff_base.clone()
+ }
+
/// Updates the `diff_base` and optionally the document if `doc` is not None
pub fn update_diff_base(&mut self, diff_base: Rope, doc: Option<Rope>) {
self.interned.clear();
diff --git a/helix-vcs/src/diff/worker.rs b/helix-vcs/src/diff/worker.rs
index f4bb4dbf..5406446f 100644
--- a/helix-vcs/src/diff/worker.rs
+++ b/helix-vcs/src/diff/worker.rs
@@ -10,7 +10,7 @@ use tokio::sync::Notify;
use tokio::time::{timeout, timeout_at, Duration};
use crate::diff::{
- Event, RenderLock, ALGORITHM, DIFF_DEBOUNCE_TIME_ASYNC, DIFF_DEBOUNCE_TIME_SYNC,
+ DiffInner, Event, RenderLock, ALGORITHM, DIFF_DEBOUNCE_TIME_ASYNC, DIFF_DEBOUNCE_TIME_SYNC,
};
use super::line_cache::InternedRopeLines;
@@ -21,7 +21,7 @@ mod test;
pub(super) struct DiffWorker {
pub channel: UnboundedReceiver<Event>,
- pub hunks: Arc<Mutex<Vec<Hunk>>>,
+ pub diff: Arc<Mutex<DiffInner>>,
pub new_hunks: Vec<Hunk>,
pub redraw_notify: Arc<Notify>,
pub diff_finished_notify: Arc<Notify>,
@@ -46,7 +46,7 @@ impl DiffWorker {
if let Some(lines) = interner.interned_lines() {
self.perform_diff(lines);
}
- self.apply_hunks();
+ self.apply_hunks(interner.diff_base(), interner.doc());
while let Some(event) = self.channel.recv().await {
let (doc, diff_base) = self.accumulate_events(event).await;
@@ -70,15 +70,18 @@ impl DiffWorker {
#[cfg(not(test))]
tokio::task::block_in_place(process_accumulated_events);
- self.apply_hunks();
+ self.apply_hunks(interner.diff_base(), interner.doc());
}
}
/// update the hunks (used by the gutter) by replacing it with `self.new_hunks`.
/// `self.new_hunks` is always empty after this function runs.
/// To improve performance this function tries to reuse the allocation of the old diff previously stored in `self.line_diffs`
- fn apply_hunks(&mut self) {
- swap(&mut *self.hunks.lock(), &mut self.new_hunks);
+ fn apply_hunks(&mut self, diff_base: Rope, doc: Rope) {
+ let mut diff = self.diff.lock();
+ diff.diff_base = diff_base;
+ diff.doc = doc;
+ swap(&mut diff.hunks, &mut self.new_hunks);
self.diff_finished_notify.notify_waiters();
self.new_hunks.clear();
}
diff --git a/helix-vcs/src/diff/worker/test.rs b/helix-vcs/src/diff/worker/test.rs
index 14442426..6a68d987 100644
--- a/helix-vcs/src/diff/worker/test.rs
+++ b/helix-vcs/src/diff/worker/test.rs
@@ -12,12 +12,12 @@ impl DiffHandle {
)
}
async fn into_diff(self, handle: JoinHandle<()>) -> Vec<Hunk> {
- let hunks = self.hunks;
+ let diff = self.diff;
// dropping the channel terminates the task
drop(self.channel);
handle.await.unwrap();
- let hunks = hunks.lock();
- Vec::clone(&*hunks)
+ let diff = diff.lock();
+ Vec::clone(&diff.hunks)
}
}