mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-03 19:07:44 +03:00
transition to nucleo for fuzzy matching (#7814)
* transition to nucleo for fuzzy matching * drop flakey test case since the picker streams in results now any test that relies on the picker containing results is potentially flakely * use crates.io version of nucleo * Fix typo in commands.rs Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com> --------- Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
This commit is contained in:
parent
40d7e6c9c8
commit
0cb595e226
26 changed files with 756 additions and 1051 deletions
|
@ -12,6 +12,7 @@ homepage = "https://helix-editor.com"
|
|||
|
||||
[dependencies]
|
||||
helix-core = { version = "0.6", path = "../helix-core" }
|
||||
helix-event = { version = "0.6", path = "../helix-event" }
|
||||
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] }
|
||||
parking_lot = "0.12"
|
||||
|
|
|
@ -2,10 +2,10 @@ use std::ops::Range;
|
|||
use std::sync::Arc;
|
||||
|
||||
use helix_core::Rope;
|
||||
use helix_event::RenderLockGuard;
|
||||
use imara_diff::Algorithm;
|
||||
use parking_lot::{Mutex, MutexGuard};
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
|
||||
use tokio::sync::{Notify, OwnedRwLockReadGuard, RwLock};
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::time::Instant;
|
||||
|
||||
|
@ -14,11 +14,9 @@ use crate::diff::worker::DiffWorker;
|
|||
mod line_cache;
|
||||
mod worker;
|
||||
|
||||
type RedrawHandle = (Arc<Notify>, Arc<RwLock<()>>);
|
||||
|
||||
/// A rendering lock passed to the differ the prevents redraws from occurring
|
||||
struct RenderLock {
|
||||
pub lock: OwnedRwLockReadGuard<()>,
|
||||
pub lock: RenderLockGuard,
|
||||
pub timeout: Option<Instant>,
|
||||
}
|
||||
|
||||
|
@ -38,28 +36,22 @@ struct DiffInner {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct DiffHandle {
|
||||
channel: UnboundedSender<Event>,
|
||||
render_lock: Arc<RwLock<()>>,
|
||||
diff: Arc<Mutex<DiffInner>>,
|
||||
inverted: bool,
|
||||
}
|
||||
|
||||
impl DiffHandle {
|
||||
pub fn new(diff_base: Rope, doc: Rope, redraw_handle: RedrawHandle) -> DiffHandle {
|
||||
DiffHandle::new_with_handle(diff_base, doc, redraw_handle).0
|
||||
pub fn new(diff_base: Rope, doc: Rope) -> DiffHandle {
|
||||
DiffHandle::new_with_handle(diff_base, doc).0
|
||||
}
|
||||
|
||||
fn new_with_handle(
|
||||
diff_base: Rope,
|
||||
doc: Rope,
|
||||
redraw_handle: RedrawHandle,
|
||||
) -> (DiffHandle, JoinHandle<()>) {
|
||||
fn new_with_handle(diff_base: Rope, doc: Rope) -> (DiffHandle, JoinHandle<()>) {
|
||||
let (sender, receiver) = unbounded_channel();
|
||||
let diff: Arc<Mutex<DiffInner>> = Arc::default();
|
||||
let worker = DiffWorker {
|
||||
channel: receiver,
|
||||
diff: diff.clone(),
|
||||
new_hunks: Vec::default(),
|
||||
redraw_notify: redraw_handle.0,
|
||||
diff_finished_notify: Arc::default(),
|
||||
};
|
||||
let handle = tokio::spawn(worker.run(diff_base, doc));
|
||||
|
@ -67,7 +59,6 @@ impl DiffHandle {
|
|||
channel: sender,
|
||||
diff,
|
||||
inverted: false,
|
||||
render_lock: redraw_handle.1,
|
||||
};
|
||||
(differ, handle)
|
||||
}
|
||||
|
@ -87,11 +78,7 @@ impl DiffHandle {
|
|||
/// This function is only intended to be called from within the rendering loop
|
||||
/// if called from elsewhere it may fail to acquire the render lock and panic
|
||||
pub fn update_document(&self, doc: Rope, block: bool) -> bool {
|
||||
// unwrap is ok here because the rendering lock is
|
||||
// only exclusively locked during redraw.
|
||||
// This function is only intended to be called
|
||||
// from the core rendering loop where no redraw can happen in parallel
|
||||
let lock = self.render_lock.clone().try_read_owned().unwrap();
|
||||
let lock = helix_event::lock_frame();
|
||||
let timeout = if block {
|
||||
None
|
||||
} else {
|
||||
|
|
|
@ -23,7 +23,6 @@ pub(super) struct DiffWorker {
|
|||
pub channel: UnboundedReceiver<Event>,
|
||||
pub diff: Arc<Mutex<DiffInner>>,
|
||||
pub new_hunks: Vec<Hunk>,
|
||||
pub redraw_notify: Arc<Notify>,
|
||||
pub diff_finished_notify: Arc<Notify>,
|
||||
}
|
||||
|
||||
|
@ -32,11 +31,7 @@ impl DiffWorker {
|
|||
let mut accumulator = EventAccumulator::new();
|
||||
accumulator.handle_event(event).await;
|
||||
accumulator
|
||||
.accumulate_debounced_events(
|
||||
&mut self.channel,
|
||||
self.redraw_notify.clone(),
|
||||
self.diff_finished_notify.clone(),
|
||||
)
|
||||
.accumulate_debounced_events(&mut self.channel, self.diff_finished_notify.clone())
|
||||
.await;
|
||||
(accumulator.doc, accumulator.diff_base)
|
||||
}
|
||||
|
@ -137,7 +132,6 @@ impl<'a> EventAccumulator {
|
|||
async fn accumulate_debounced_events(
|
||||
&mut self,
|
||||
channel: &mut UnboundedReceiver<Event>,
|
||||
redraw_notify: Arc<Notify>,
|
||||
diff_finished_notify: Arc<Notify>,
|
||||
) {
|
||||
let async_debounce = Duration::from_millis(DIFF_DEBOUNCE_TIME_ASYNC);
|
||||
|
@ -164,7 +158,7 @@ impl<'a> EventAccumulator {
|
|||
None => {
|
||||
tokio::spawn(async move {
|
||||
diff_finished_notify.notified().await;
|
||||
redraw_notify.notify_one();
|
||||
helix_event::request_redraw();
|
||||
});
|
||||
}
|
||||
// diff is performed inside the rendering loop
|
||||
|
@ -190,7 +184,7 @@ impl<'a> EventAccumulator {
|
|||
// and wait until the diff occurs to trigger an async redraw
|
||||
log::info!("Diff computation timed out, update of diffs might appear delayed");
|
||||
diff_finished_notify.notified().await;
|
||||
redraw_notify.notify_one();
|
||||
helix_event::request_redraw()
|
||||
});
|
||||
}
|
||||
// a blocking diff is performed inside the rendering loop
|
||||
|
|
|
@ -5,11 +5,7 @@ use crate::diff::{DiffHandle, Hunk};
|
|||
|
||||
impl DiffHandle {
|
||||
fn new_test(diff_base: &str, doc: &str) -> (DiffHandle, JoinHandle<()>) {
|
||||
DiffHandle::new_with_handle(
|
||||
Rope::from_str(diff_base),
|
||||
Rope::from_str(doc),
|
||||
Default::default(),
|
||||
)
|
||||
DiffHandle::new_with_handle(Rope::from_str(diff_base), Rope::from_str(doc))
|
||||
}
|
||||
async fn into_diff(self, handle: JoinHandle<()>) -> Vec<Hunk> {
|
||||
let diff = self.diff;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue