aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/imp.rs63
-rw-r--r--crates/ra_analysis/src/lib.rs8
2 files changed, 26 insertions, 45 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 248b77f5a..d9a3f97e9 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -27,32 +27,25 @@ use crate::{
27 symbol_index::{LibrarySymbolsQuery, FileSymbol}, 27 symbol_index::{LibrarySymbolsQuery, FileSymbol},
28}; 28};
29 29
30#[derive(Debug, Default)] 30impl db::RootDatabase {
31pub(crate) struct AnalysisHostImpl { 31 pub(crate) fn analysis(&self) -> AnalysisImpl {
32 db: db::RootDatabase,
33}
34
35impl AnalysisHostImpl {
36 pub fn analysis(&self) -> AnalysisImpl {
37 AnalysisImpl { 32 AnalysisImpl {
38 db: self.db.snapshot(), 33 db: self.snapshot(),
39 } 34 }
40 } 35 }
41 pub fn apply_change(&mut self, change: AnalysisChange) { 36 pub(crate) fn apply_change(&mut self, change: AnalysisChange) {
42 log::info!("apply_change {:?}", change); 37 log::info!("apply_change {:?}", change);
43 // self.gc_syntax_trees(); 38 // self.gc_syntax_trees();
44 if !change.new_roots.is_empty() { 39 if !change.new_roots.is_empty() {
45 let mut local_roots = Vec::clone(&self.db.local_roots()); 40 let mut local_roots = Vec::clone(&self.local_roots());
46 for (root_id, is_local) in change.new_roots { 41 for (root_id, is_local) in change.new_roots {
47 self.db 42 self.query_mut(ra_db::SourceRootQuery)
48 .query_mut(ra_db::SourceRootQuery)
49 .set(root_id, Default::default()); 43 .set(root_id, Default::default());
50 if is_local { 44 if is_local {
51 local_roots.push(root_id); 45 local_roots.push(root_id);
52 } 46 }
53 } 47 }
54 self.db 48 self.query_mut(ra_db::LocalRootsQuery)
55 .query_mut(ra_db::LocalRootsQuery)
56 .set((), Arc::new(local_roots)); 49 .set((), Arc::new(local_roots));
57 } 50 }
58 51
@@ -60,53 +53,44 @@ impl AnalysisHostImpl {
60 self.apply_root_change(root_id, root_change); 53 self.apply_root_change(root_id, root_change);
61 } 54 }
62 for (file_id, text) in change.files_changed { 55 for (file_id, text) in change.files_changed {
63 self.db.query_mut(ra_db::FileTextQuery).set(file_id, text) 56 self.query_mut(ra_db::FileTextQuery).set(file_id, text)
64 } 57 }
65 if !change.libraries_added.is_empty() { 58 if !change.libraries_added.is_empty() {
66 let mut libraries = Vec::clone(&self.db.library_roots()); 59 let mut libraries = Vec::clone(&self.library_roots());
67 for library in change.libraries_added { 60 for library in change.libraries_added {
68 libraries.push(library.root_id); 61 libraries.push(library.root_id);
69 self.db 62 self.query_mut(ra_db::SourceRootQuery)
70 .query_mut(ra_db::SourceRootQuery)
71 .set(library.root_id, Default::default()); 63 .set(library.root_id, Default::default());
72 self.db 64 self.query_mut(LibrarySymbolsQuery)
73 .query_mut(LibrarySymbolsQuery)
74 .set_constant(library.root_id, Arc::new(library.symbol_index)); 65 .set_constant(library.root_id, Arc::new(library.symbol_index));
75 self.apply_root_change(library.root_id, library.root_change); 66 self.apply_root_change(library.root_id, library.root_change);
76 } 67 }
77 self.db 68 self.query_mut(ra_db::LibraryRootsQuery)
78 .query_mut(ra_db::LibraryRootsQuery)
79 .set((), Arc::new(libraries)); 69 .set((), Arc::new(libraries));
80 } 70 }
81 if let Some(crate_graph) = change.crate_graph { 71 if let Some(crate_graph) = change.crate_graph {
82 self.db 72 self.query_mut(ra_db::CrateGraphQuery)
83 .query_mut(ra_db::CrateGraphQuery)
84 .set((), Arc::new(crate_graph)) 73 .set((), Arc::new(crate_graph))
85 } 74 }
86 } 75 }
87 76
88 fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { 77 fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
89 let mut source_root = SourceRoot::clone(&self.db.source_root(root_id)); 78 let mut source_root = SourceRoot::clone(&self.source_root(root_id));
90 for add_file in root_change.added { 79 for add_file in root_change.added {
91 self.db 80 self.query_mut(ra_db::FileTextQuery)
92 .query_mut(ra_db::FileTextQuery)
93 .set(add_file.file_id, add_file.text); 81 .set(add_file.file_id, add_file.text);
94 self.db 82 self.query_mut(ra_db::FileRelativePathQuery)
95 .query_mut(ra_db::FileRelativePathQuery)
96 .set(add_file.file_id, add_file.path.clone()); 83 .set(add_file.file_id, add_file.path.clone());
97 self.db 84 self.query_mut(ra_db::FileSourceRootQuery)
98 .query_mut(ra_db::FileSourceRootQuery)
99 .set(add_file.file_id, root_id); 85 .set(add_file.file_id, root_id);
100 source_root.files.insert(add_file.path, add_file.file_id); 86 source_root.files.insert(add_file.path, add_file.file_id);
101 } 87 }
102 for remove_file in root_change.removed { 88 for remove_file in root_change.removed {
103 self.db 89 self.query_mut(ra_db::FileTextQuery)
104 .query_mut(ra_db::FileTextQuery)
105 .set(remove_file.file_id, Default::default()); 90 .set(remove_file.file_id, Default::default());
106 source_root.files.remove(&remove_file.path); 91 source_root.files.remove(&remove_file.path);
107 } 92 }
108 self.db 93 self.query_mut(ra_db::SourceRootQuery)
109 .query_mut(ra_db::SourceRootQuery)
110 .set(root_id, Arc::new(source_root)); 94 .set(root_id, Arc::new(source_root));
111 } 95 }
112 96
@@ -115,14 +99,11 @@ impl AnalysisHostImpl {
115 /// syntax trees. However, if we actually do that, everything is recomputed 99 /// syntax trees. However, if we actually do that, everything is recomputed
116 /// for some reason. Needs investigation. 100 /// for some reason. Needs investigation.
117 fn gc_syntax_trees(&mut self) { 101 fn gc_syntax_trees(&mut self) {
118 self.db 102 self.query(ra_db::SourceFileQuery)
119 .query(ra_db::SourceFileQuery)
120 .sweep(salsa::SweepStrategy::default().discard_values()); 103 .sweep(salsa::SweepStrategy::default().discard_values());
121 self.db 104 self.query(hir::db::SourceFileItemsQuery)
122 .query(hir::db::SourceFileItemsQuery)
123 .sweep(salsa::SweepStrategy::default().discard_values()); 105 .sweep(salsa::SweepStrategy::default().discard_values());
124 self.db 106 self.query(hir::db::FileItemQuery)
125 .query(hir::db::FileItemQuery)
126 .sweep(salsa::SweepStrategy::default().discard_values()); 107 .sweep(salsa::SweepStrategy::default().discard_values());
127 } 108 }
128} 109}
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index ef08a721c..03994b7c4 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -29,7 +29,7 @@ use rayon::prelude::*;
29use relative_path::RelativePathBuf; 29use relative_path::RelativePathBuf;
30 30
31use crate::{ 31use crate::{
32 imp::{AnalysisHostImpl, AnalysisImpl}, 32 imp::AnalysisImpl,
33 symbol_index::{SymbolIndex, FileSymbol}, 33 symbol_index::{SymbolIndex, FileSymbol},
34}; 34};
35 35
@@ -153,7 +153,7 @@ impl AnalysisChange {
153/// `AnalysisHost` stores the current state of the world. 153/// `AnalysisHost` stores the current state of the world.
154#[derive(Debug, Default)] 154#[derive(Debug, Default)]
155pub struct AnalysisHost { 155pub struct AnalysisHost {
156 imp: AnalysisHostImpl, 156 db: db::RootDatabase,
157} 157}
158 158
159impl AnalysisHost { 159impl AnalysisHost {
@@ -161,13 +161,13 @@ impl AnalysisHost {
161 /// semantic information. 161 /// semantic information.
162 pub fn analysis(&self) -> Analysis { 162 pub fn analysis(&self) -> Analysis {
163 Analysis { 163 Analysis {
164 imp: self.imp.analysis(), 164 imp: self.db.analysis(),
165 } 165 }
166 } 166 }
167 /// Applies changes to the current state of the world. If there are 167 /// Applies changes to the current state of the world. If there are
168 /// outstanding snapshots, they will be canceled. 168 /// outstanding snapshots, they will be canceled.
169 pub fn apply_change(&mut self, change: AnalysisChange) { 169 pub fn apply_change(&mut self, change: AnalysisChange) {
170 self.imp.apply_change(change) 170 self.db.apply_change(change)
171 } 171 }
172} 172}
173 173