mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
project model
This commit is contained in:
parent
7fad13de73
commit
80be61ed78
11 changed files with 251 additions and 78 deletions
|
@ -1,14 +1,14 @@
|
|||
use std::{
|
||||
path::PathBuf,
|
||||
thread,
|
||||
fs,
|
||||
};
|
||||
|
||||
use crossbeam_channel::{Sender, Receiver, bounded};
|
||||
use drop_bomb::DropBomb;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use Result;
|
||||
use {
|
||||
thread_watcher::ThreadWatcher,
|
||||
};
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -24,26 +24,10 @@ pub enum FileEventKind {
|
|||
Remove,
|
||||
}
|
||||
|
||||
pub struct Watcher {
|
||||
thread: thread::JoinHandle<()>,
|
||||
bomb: DropBomb,
|
||||
}
|
||||
|
||||
impl Watcher {
|
||||
pub fn stop(mut self) -> Result<()> {
|
||||
self.bomb.defuse();
|
||||
self.thread.join()
|
||||
.map_err(|_| format_err!("file watcher died"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn watch(roots: Vec<PathBuf>) -> (Receiver<Vec<FileEvent>>, Watcher) {
|
||||
pub fn watch(roots: Vec<PathBuf>) -> (Receiver<Vec<FileEvent>>, ThreadWatcher) {
|
||||
let (sender, receiver) = bounded(16);
|
||||
let thread = thread::spawn(move || run(roots, sender));
|
||||
(receiver, Watcher {
|
||||
thread,
|
||||
bomb: DropBomb::new("Watcher should be stopped explicitly"),
|
||||
})
|
||||
let watcher = ThreadWatcher::spawn("vfs", move || run(roots, sender));
|
||||
(receiver, watcher)
|
||||
}
|
||||
|
||||
fn run(roots: Vec<PathBuf>, sender: Sender<Vec<FileEvent>>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue