This commit is contained in:
Aleksey Kladov 2018-12-20 12:05:29 +03:00
parent 97812c192a
commit 6782fe2a5b

View file

@ -73,8 +73,8 @@ impl AnalysisHostImpl {
.set(library.root_id, Default::default());
self.db
.query_mut(LibrarySymbolsQuery)
.set(library.root_id, Arc::new(library.symbol_index));
self.apply_root_change(library.root_id, library.root_change);
.set_constant(library.root_id, Arc::new(library.symbol_index));
self.apply_root_change_constant(library.root_id, library.root_change);
}
self.db
.query_mut(ra_db::LibraryRootsQuery)
@ -115,6 +115,34 @@ impl AnalysisHostImpl {
.set(root_id, Arc::new(source_root));
}
fn apply_root_change_constant(&mut self, root_id: SourceRootId, root_change: RootChange) {
let mut source_root = SourceRoot::clone(&self.db.source_root(root_id));
for add_file in root_change.added {
self.db
.query_mut(ra_db::FileTextQuery)
.set_constant(add_file.file_id, add_file.text);
self.db
.query_mut(ra_db::FileRelativePathQuery)
.set_constant(add_file.file_id, add_file.path.clone());
self.db
.query_mut(ra_db::FileSourceRootQuery)
.set_constant(add_file.file_id, root_id);
source_root.files.insert(add_file.path, add_file.file_id);
}
for remove_file in root_change.removed {
self.db
.query_mut(ra_db::FileTextQuery)
.set_constant(remove_file.file_id, Default::default());
self.db
.query_mut(ra_db::FileRelativePathQuery)
.set_constant(remove_file.file_id, Default::default());
source_root.files.remove(&remove_file.path);
}
self.db
.query_mut(ra_db::SourceRootQuery)
.set_constant(root_id, Arc::new(source_root));
}
#[allow(unused)]
/// Ideally, we should call this function from time to time to collect heavy
/// syntax trees. However, if we actually do that, everything is recomputed