mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-05 02:20:10 +00:00
WIP
This commit is contained in:
parent
48ad3866b7
commit
2bc7be9a76
1 changed files with 29 additions and 11 deletions
|
@ -2399,10 +2399,15 @@ struct BackgroundScanner {
|
||||||
status_updates_tx: UnboundedSender<ScanState>,
|
status_updates_tx: UnboundedSender<ScanState>,
|
||||||
executor: Arc<executor::Background>,
|
executor: Arc<executor::Background>,
|
||||||
refresh_requests_rx: channel::Receiver<(Vec<PathBuf>, barrier::Sender)>,
|
refresh_requests_rx: channel::Receiver<(Vec<PathBuf>, barrier::Sender)>,
|
||||||
prev_state: Mutex<(Snapshot, Vec<Arc<Path>>)>,
|
prev_state: Mutex<BackgroundScannerState>,
|
||||||
finished_initial_scan: bool,
|
finished_initial_scan: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BackgroundScannerState {
|
||||||
|
snapshot: Snapshot,
|
||||||
|
event_paths: Vec<Arc<Path>>,
|
||||||
|
}
|
||||||
|
|
||||||
impl BackgroundScanner {
|
impl BackgroundScanner {
|
||||||
fn new(
|
fn new(
|
||||||
snapshot: LocalSnapshot,
|
snapshot: LocalSnapshot,
|
||||||
|
@ -2416,7 +2421,10 @@ impl BackgroundScanner {
|
||||||
status_updates_tx,
|
status_updates_tx,
|
||||||
executor,
|
executor,
|
||||||
refresh_requests_rx,
|
refresh_requests_rx,
|
||||||
prev_state: Mutex::new((snapshot.snapshot.clone(), Vec::new())),
|
prev_state: Mutex::new(BackgroundScannerState {
|
||||||
|
snapshot: snapshot.snapshot.clone(),
|
||||||
|
event_paths: Default::default(),
|
||||||
|
}),
|
||||||
snapshot: Mutex::new(snapshot),
|
snapshot: Mutex::new(snapshot),
|
||||||
finished_initial_scan: false,
|
finished_initial_scan: false,
|
||||||
}
|
}
|
||||||
|
@ -2526,7 +2534,12 @@ impl BackgroundScanner {
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
paths.sort_unstable();
|
paths.sort_unstable();
|
||||||
util::extend_sorted(&mut self.prev_state.lock().1, paths, usize::MAX, Ord::cmp);
|
util::extend_sorted(
|
||||||
|
&mut self.prev_state.lock().event_paths,
|
||||||
|
paths,
|
||||||
|
usize::MAX,
|
||||||
|
Ord::cmp,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
drop(scan_job_tx);
|
drop(scan_job_tx);
|
||||||
self.scan_dirs(false, scan_job_rx).await;
|
self.scan_dirs(false, scan_job_rx).await;
|
||||||
|
@ -2560,6 +2573,7 @@ impl BackgroundScanner {
|
||||||
drop(snapshot);
|
drop(snapshot);
|
||||||
|
|
||||||
self.send_status_update(false, None);
|
self.send_status_update(false, None);
|
||||||
|
self.prev_state.lock().event_paths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn scan_dirs(
|
async fn scan_dirs(
|
||||||
|
@ -2637,14 +2651,18 @@ impl BackgroundScanner {
|
||||||
|
|
||||||
fn send_status_update(&self, scanning: bool, barrier: Option<barrier::Sender>) -> bool {
|
fn send_status_update(&self, scanning: bool, barrier: Option<barrier::Sender>) -> bool {
|
||||||
let mut prev_state = self.prev_state.lock();
|
let mut prev_state = self.prev_state.lock();
|
||||||
let snapshot = self.snapshot.lock().clone();
|
let new_snapshot = self.snapshot.lock().clone();
|
||||||
let mut old_snapshot = snapshot.snapshot.clone();
|
let old_snapshot = mem::replace(&mut prev_state.snapshot, new_snapshot.snapshot.clone());
|
||||||
mem::swap(&mut old_snapshot, &mut prev_state.0);
|
|
||||||
let changed_paths = mem::take(&mut prev_state.1);
|
let changes = self.build_change_set(
|
||||||
let changes = self.build_change_set(&old_snapshot, &snapshot.snapshot, changed_paths);
|
&old_snapshot,
|
||||||
|
&new_snapshot.snapshot,
|
||||||
|
&prev_state.event_paths,
|
||||||
|
);
|
||||||
|
|
||||||
self.status_updates_tx
|
self.status_updates_tx
|
||||||
.unbounded_send(ScanState::Updated {
|
.unbounded_send(ScanState::Updated {
|
||||||
snapshot,
|
snapshot: new_snapshot,
|
||||||
changes,
|
changes,
|
||||||
scanning,
|
scanning,
|
||||||
barrier,
|
barrier,
|
||||||
|
@ -3012,7 +3030,7 @@ impl BackgroundScanner {
|
||||||
&self,
|
&self,
|
||||||
old_snapshot: &Snapshot,
|
old_snapshot: &Snapshot,
|
||||||
new_snapshot: &Snapshot,
|
new_snapshot: &Snapshot,
|
||||||
event_paths: Vec<Arc<Path>>,
|
event_paths: &[Arc<Path>],
|
||||||
) -> HashMap<Arc<Path>, PathChange> {
|
) -> HashMap<Arc<Path>, PathChange> {
|
||||||
use PathChange::{Added, AddedOrUpdated, Removed, Updated};
|
use PathChange::{Added, AddedOrUpdated, Removed, Updated};
|
||||||
|
|
||||||
|
@ -3022,7 +3040,7 @@ impl BackgroundScanner {
|
||||||
let received_before_initialized = !self.finished_initial_scan;
|
let received_before_initialized = !self.finished_initial_scan;
|
||||||
|
|
||||||
for path in event_paths {
|
for path in event_paths {
|
||||||
let path = PathKey(path);
|
let path = PathKey(path.clone());
|
||||||
old_paths.seek(&path, Bias::Left, &());
|
old_paths.seek(&path, Bias::Left, &());
|
||||||
new_paths.seek(&path, Bias::Left, &());
|
new_paths.seek(&path, Bias::Left, &());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue