mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
remove AnalysisHostImpl
This commit is contained in:
parent
2f22c861a9
commit
e9b47dbb36
2 changed files with 26 additions and 45 deletions
|
@ -27,32 +27,25 @@ use crate::{
|
||||||
symbol_index::{LibrarySymbolsQuery, FileSymbol},
|
symbol_index::{LibrarySymbolsQuery, FileSymbol},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
impl db::RootDatabase {
|
||||||
pub(crate) struct AnalysisHostImpl {
|
pub(crate) fn analysis(&self) -> AnalysisImpl {
|
||||||
db: db::RootDatabase,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnalysisHostImpl {
|
|
||||||
pub fn analysis(&self) -> AnalysisImpl {
|
|
||||||
AnalysisImpl {
|
AnalysisImpl {
|
||||||
db: self.db.snapshot(),
|
db: self.snapshot(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn apply_change(&mut self, change: AnalysisChange) {
|
pub(crate) fn apply_change(&mut self, change: AnalysisChange) {
|
||||||
log::info!("apply_change {:?}", change);
|
log::info!("apply_change {:?}", change);
|
||||||
// self.gc_syntax_trees();
|
// self.gc_syntax_trees();
|
||||||
if !change.new_roots.is_empty() {
|
if !change.new_roots.is_empty() {
|
||||||
let mut local_roots = Vec::clone(&self.db.local_roots());
|
let mut local_roots = Vec::clone(&self.local_roots());
|
||||||
for (root_id, is_local) in change.new_roots {
|
for (root_id, is_local) in change.new_roots {
|
||||||
self.db
|
self.query_mut(ra_db::SourceRootQuery)
|
||||||
.query_mut(ra_db::SourceRootQuery)
|
|
||||||
.set(root_id, Default::default());
|
.set(root_id, Default::default());
|
||||||
if is_local {
|
if is_local {
|
||||||
local_roots.push(root_id);
|
local_roots.push(root_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.db
|
self.query_mut(ra_db::LocalRootsQuery)
|
||||||
.query_mut(ra_db::LocalRootsQuery)
|
|
||||||
.set((), Arc::new(local_roots));
|
.set((), Arc::new(local_roots));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,53 +53,44 @@ impl AnalysisHostImpl {
|
||||||
self.apply_root_change(root_id, root_change);
|
self.apply_root_change(root_id, root_change);
|
||||||
}
|
}
|
||||||
for (file_id, text) in change.files_changed {
|
for (file_id, text) in change.files_changed {
|
||||||
self.db.query_mut(ra_db::FileTextQuery).set(file_id, text)
|
self.query_mut(ra_db::FileTextQuery).set(file_id, text)
|
||||||
}
|
}
|
||||||
if !change.libraries_added.is_empty() {
|
if !change.libraries_added.is_empty() {
|
||||||
let mut libraries = Vec::clone(&self.db.library_roots());
|
let mut libraries = Vec::clone(&self.library_roots());
|
||||||
for library in change.libraries_added {
|
for library in change.libraries_added {
|
||||||
libraries.push(library.root_id);
|
libraries.push(library.root_id);
|
||||||
self.db
|
self.query_mut(ra_db::SourceRootQuery)
|
||||||
.query_mut(ra_db::SourceRootQuery)
|
|
||||||
.set(library.root_id, Default::default());
|
.set(library.root_id, Default::default());
|
||||||
self.db
|
self.query_mut(LibrarySymbolsQuery)
|
||||||
.query_mut(LibrarySymbolsQuery)
|
|
||||||
.set_constant(library.root_id, Arc::new(library.symbol_index));
|
.set_constant(library.root_id, Arc::new(library.symbol_index));
|
||||||
self.apply_root_change(library.root_id, library.root_change);
|
self.apply_root_change(library.root_id, library.root_change);
|
||||||
}
|
}
|
||||||
self.db
|
self.query_mut(ra_db::LibraryRootsQuery)
|
||||||
.query_mut(ra_db::LibraryRootsQuery)
|
|
||||||
.set((), Arc::new(libraries));
|
.set((), Arc::new(libraries));
|
||||||
}
|
}
|
||||||
if let Some(crate_graph) = change.crate_graph {
|
if let Some(crate_graph) = change.crate_graph {
|
||||||
self.db
|
self.query_mut(ra_db::CrateGraphQuery)
|
||||||
.query_mut(ra_db::CrateGraphQuery)
|
|
||||||
.set((), Arc::new(crate_graph))
|
.set((), Arc::new(crate_graph))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
|
fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
|
||||||
let mut source_root = SourceRoot::clone(&self.db.source_root(root_id));
|
let mut source_root = SourceRoot::clone(&self.source_root(root_id));
|
||||||
for add_file in root_change.added {
|
for add_file in root_change.added {
|
||||||
self.db
|
self.query_mut(ra_db::FileTextQuery)
|
||||||
.query_mut(ra_db::FileTextQuery)
|
|
||||||
.set(add_file.file_id, add_file.text);
|
.set(add_file.file_id, add_file.text);
|
||||||
self.db
|
self.query_mut(ra_db::FileRelativePathQuery)
|
||||||
.query_mut(ra_db::FileRelativePathQuery)
|
|
||||||
.set(add_file.file_id, add_file.path.clone());
|
.set(add_file.file_id, add_file.path.clone());
|
||||||
self.db
|
self.query_mut(ra_db::FileSourceRootQuery)
|
||||||
.query_mut(ra_db::FileSourceRootQuery)
|
|
||||||
.set(add_file.file_id, root_id);
|
.set(add_file.file_id, root_id);
|
||||||
source_root.files.insert(add_file.path, add_file.file_id);
|
source_root.files.insert(add_file.path, add_file.file_id);
|
||||||
}
|
}
|
||||||
for remove_file in root_change.removed {
|
for remove_file in root_change.removed {
|
||||||
self.db
|
self.query_mut(ra_db::FileTextQuery)
|
||||||
.query_mut(ra_db::FileTextQuery)
|
|
||||||
.set(remove_file.file_id, Default::default());
|
.set(remove_file.file_id, Default::default());
|
||||||
source_root.files.remove(&remove_file.path);
|
source_root.files.remove(&remove_file.path);
|
||||||
}
|
}
|
||||||
self.db
|
self.query_mut(ra_db::SourceRootQuery)
|
||||||
.query_mut(ra_db::SourceRootQuery)
|
|
||||||
.set(root_id, Arc::new(source_root));
|
.set(root_id, Arc::new(source_root));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,14 +99,11 @@ impl AnalysisHostImpl {
|
||||||
/// syntax trees. However, if we actually do that, everything is recomputed
|
/// syntax trees. However, if we actually do that, everything is recomputed
|
||||||
/// for some reason. Needs investigation.
|
/// for some reason. Needs investigation.
|
||||||
fn gc_syntax_trees(&mut self) {
|
fn gc_syntax_trees(&mut self) {
|
||||||
self.db
|
self.query(ra_db::SourceFileQuery)
|
||||||
.query(ra_db::SourceFileQuery)
|
|
||||||
.sweep(salsa::SweepStrategy::default().discard_values());
|
.sweep(salsa::SweepStrategy::default().discard_values());
|
||||||
self.db
|
self.query(hir::db::SourceFileItemsQuery)
|
||||||
.query(hir::db::SourceFileItemsQuery)
|
|
||||||
.sweep(salsa::SweepStrategy::default().discard_values());
|
.sweep(salsa::SweepStrategy::default().discard_values());
|
||||||
self.db
|
self.query(hir::db::FileItemQuery)
|
||||||
.query(hir::db::FileItemQuery)
|
|
||||||
.sweep(salsa::SweepStrategy::default().discard_values());
|
.sweep(salsa::SweepStrategy::default().discard_values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ use rayon::prelude::*;
|
||||||
use relative_path::RelativePathBuf;
|
use relative_path::RelativePathBuf;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
imp::{AnalysisHostImpl, AnalysisImpl},
|
imp::AnalysisImpl,
|
||||||
symbol_index::{SymbolIndex, FileSymbol},
|
symbol_index::{SymbolIndex, FileSymbol},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ impl AnalysisChange {
|
||||||
/// `AnalysisHost` stores the current state of the world.
|
/// `AnalysisHost` stores the current state of the world.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AnalysisHost {
|
pub struct AnalysisHost {
|
||||||
imp: AnalysisHostImpl,
|
db: db::RootDatabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnalysisHost {
|
impl AnalysisHost {
|
||||||
|
@ -161,13 +161,13 @@ impl AnalysisHost {
|
||||||
/// semantic information.
|
/// semantic information.
|
||||||
pub fn analysis(&self) -> Analysis {
|
pub fn analysis(&self) -> Analysis {
|
||||||
Analysis {
|
Analysis {
|
||||||
imp: self.imp.analysis(),
|
imp: self.db.analysis(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Applies changes to the current state of the world. If there are
|
/// Applies changes to the current state of the world. If there are
|
||||||
/// outstanding snapshots, they will be canceled.
|
/// outstanding snapshots, they will be canceled.
|
||||||
pub fn apply_change(&mut self, change: AnalysisChange) {
|
pub fn apply_change(&mut self, change: AnalysisChange) {
|
||||||
self.imp.apply_change(change)
|
self.db.apply_change(change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue