Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-vcs/src/diff.rs')
| -rw-r--r-- | helix-vcs/src/diff.rs | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/helix-vcs/src/diff.rs b/helix-vcs/src/diff.rs index e49e171d..6ec29813 100644 --- a/helix-vcs/src/diff.rs +++ b/helix-vcs/src/diff.rs @@ -1,5 +1,4 @@ use std::iter::Peekable; -use std::ops::Range; use std::sync::Arc; use helix_core::Rope; @@ -12,6 +11,8 @@ use tokio::time::Instant; use crate::diff::worker::DiffWorker; +pub use imara_diff::Hunk; + mod line_cache; mod worker; @@ -52,8 +53,8 @@ impl DiffHandle { let worker = DiffWorker { channel: receiver, diff: diff.clone(), - new_hunks: Vec::default(), diff_finished_notify: Arc::default(), + diff_alloc: imara_diff::Diff::default(), }; let handle = tokio::spawn(worker.run(diff_base, doc)); let differ = DiffHandle { @@ -118,48 +119,6 @@ const MAX_DIFF_LINES: usize = 64 * u16::MAX as usize; // cap average line length to 128 for files with MAX_DIFF_LINES const MAX_DIFF_BYTES: usize = MAX_DIFF_LINES * 128; -/// A single change in a file potentially spanning multiple lines -/// Hunks produced by the differs are always ordered by their position -/// in the file and non-overlapping. -/// Specifically for any two hunks `x` and `y` the following properties hold: -/// -/// ``` no_compile -/// assert!(x.before.end <= y.before.start); -/// assert!(x.after.end <= y.after.start); -/// ``` -#[derive(PartialEq, Eq, Clone, Debug)] -pub struct Hunk { - pub before: Range<u32>, - pub after: Range<u32>, -} - -impl Hunk { - /// Can be used instead of `Option::None` for better performance - /// because lines larger then `i32::MAX` are not supported by `imara-diff` anyways. - /// Has some nice properties where it usually is not necessary to check for `None` separately: - /// Empty ranges fail contains checks and also fails smaller then checks. - pub const NONE: Hunk = Hunk { - before: u32::MAX..u32::MAX, - after: u32::MAX..u32::MAX, - }; - - /// Inverts a change so that `before` - pub fn invert(&self) -> Hunk { - Hunk { - before: self.after.clone(), - after: self.before.clone(), - } - } - - pub fn is_pure_insertion(&self) -> bool { - self.before.is_empty() - } - - pub fn is_pure_removal(&self) -> bool { - self.after.is_empty() - } -} - /// A list of changes in a file sorted in ascending /// non-overlapping order #[derive(Debug)] |