mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
Optimize VFS processing
This commit is contained in:
parent
676d2e040d
commit
a1ef6cc553
@ -198,39 +198,49 @@ impl GlobalState {
|
||||
}
|
||||
self.analysis_host.maybe_collect_garbage();
|
||||
}
|
||||
Event::Vfs(task) => match task {
|
||||
vfs::loader::Message::Loaded { files } => {
|
||||
let vfs = &mut self.vfs.write().0;
|
||||
for (path, contents) in files {
|
||||
let path = VfsPath::from(path);
|
||||
if !self.mem_docs.contains(&path) {
|
||||
vfs.set_file_contents(path, contents)
|
||||
Event::Vfs(mut task) => {
|
||||
let _p = profile("GlobalState::handle_event/vfs");
|
||||
loop {
|
||||
match task {
|
||||
vfs::loader::Message::Loaded { files } => {
|
||||
let vfs = &mut self.vfs.write().0;
|
||||
for (path, contents) in files {
|
||||
let path = VfsPath::from(path);
|
||||
if !self.mem_docs.contains(&path) {
|
||||
vfs.set_file_contents(path, contents)
|
||||
}
|
||||
}
|
||||
}
|
||||
vfs::loader::Message::Progress { n_total, n_done } => {
|
||||
if n_total == 0 {
|
||||
self.transition(Status::Invalid);
|
||||
} else {
|
||||
let state = if n_done == 0 {
|
||||
self.transition(Status::Loading);
|
||||
Progress::Begin
|
||||
} else if n_done < n_total {
|
||||
Progress::Report
|
||||
} else {
|
||||
assert_eq!(n_done, n_total);
|
||||
self.transition(Status::Ready);
|
||||
Progress::End
|
||||
};
|
||||
self.report_progress(
|
||||
"roots scanned",
|
||||
state,
|
||||
Some(format!("{}/{}", n_done, n_total)),
|
||||
Some(Progress::percentage(n_done, n_total)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vfs::loader::Message::Progress { n_total, n_done } => {
|
||||
if n_total == 0 {
|
||||
self.transition(Status::Invalid);
|
||||
} else {
|
||||
let state = if n_done == 0 {
|
||||
self.transition(Status::Loading);
|
||||
Progress::Begin
|
||||
} else if n_done < n_total {
|
||||
Progress::Report
|
||||
} else {
|
||||
assert_eq!(n_done, n_total);
|
||||
self.transition(Status::Ready);
|
||||
Progress::End
|
||||
};
|
||||
self.report_progress(
|
||||
"roots scanned",
|
||||
state,
|
||||
Some(format!("{}/{}", n_done, n_total)),
|
||||
Some(Progress::percentage(n_done, n_total)),
|
||||
)
|
||||
// Coalesce many VFS event into a single loop turn
|
||||
task = match self.loader.receiver.try_recv() {
|
||||
Ok(task) => task,
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Flycheck(task) => match task {
|
||||
flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
|
||||
let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
|
||||
|
@ -70,7 +70,7 @@ impl ChangedFile {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Copy, Clone)]
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum ChangeKind {
|
||||
Create,
|
||||
Modify,
|
||||
|
Loading…
Reference in New Issue
Block a user