mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
rename all things
This commit is contained in:
parent
ba0bfeee12
commit
b5021411a8
478 changed files with 219 additions and 204 deletions
71
crates/ra_lsp_server/src/vfs.rs
Normal file
71
crates/ra_lsp_server/src/vfs.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
use std::{
|
||||
path::{PathBuf, Path},
|
||||
fs,
|
||||
};
|
||||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use {
|
||||
thread_watcher::{Worker, ThreadWatcher},
|
||||
};
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FileEvent {
|
||||
pub path: PathBuf,
|
||||
pub kind: FileEventKind,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileEventKind {
|
||||
Add(String),
|
||||
}
|
||||
|
||||
pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatcher) {
|
||||
Worker::<PathBuf, (PathBuf, Vec<FileEvent>)>::spawn(
|
||||
"roots loader",
|
||||
128, |input_receiver, output_sender| {
|
||||
input_receiver
|
||||
.into_iter()
|
||||
.map(|path| {
|
||||
debug!("loading {} ...", path.as_path().display());
|
||||
let events = load_root(path.as_path());
|
||||
debug!("... loaded {}", path.as_path().display());
|
||||
(path, events)
|
||||
})
|
||||
.for_each(|it| output_sender.send(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fn load_root(path: &Path) -> Vec<FileEvent> {
|
||||
let mut res = Vec::new();
|
||||
for entry in WalkDir::new(path) {
|
||||
let entry = match entry {
|
||||
Ok(entry) => entry,
|
||||
Err(e) => {
|
||||
warn!("watcher error: {}", e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if !entry.file_type().is_file() {
|
||||
continue;
|
||||
}
|
||||
let path = entry.path();
|
||||
if path.extension().and_then(|os| os.to_str()) != Some("rs") {
|
||||
continue;
|
||||
}
|
||||
let text = match fs::read_to_string(path) {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
warn!("watcher error: {}", e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
res.push(FileEvent {
|
||||
path: path.to_owned(),
|
||||
kind: FileEventKind::Add(text),
|
||||
})
|
||||
}
|
||||
res
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue