aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/Cargo.toml3
-rw-r--r--crates/ra_analysis/src/imp.rs25
-rw-r--r--crates/ra_analysis/src/lib.rs4
-rw-r--r--crates/ra_analysis/src/roots.rs24
4 files changed, 18 insertions, 38 deletions
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml
index 0f5ff6d24..75a9dc844 100644
--- a/crates/ra_analysis/Cargo.toml
+++ b/crates/ra_analysis/Cargo.toml
@@ -6,9 +6,6 @@ authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8relative-path = "0.4.0" 8relative-path = "0.4.0"
9log = "0.4.2"
10parking_lot = "0.6.3"
11once_cell = "0.1.5"
12rayon = "1.0.2" 9rayon = "1.0.2"
13fst = "0.3.1" 10fst = "0.3.1"
14ra_syntax = { path = "../ra_syntax" } 11ra_syntax = { path = "../ra_syntax" }
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 83a0dc445..f142b6c43 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -16,7 +16,8 @@ use relative_path::RelativePath;
16use rustc_hash::FxHashSet; 16use rustc_hash::FxHashSet;
17 17
18use crate::{ 18use crate::{
19 descriptors::module::{ModuleTree, Problem}, 19 db::SyntaxDatabase,
20 descriptors::module::{ModulesDatabase, ModuleTree, Problem},
20 descriptors::{FnDescriptor}, 21 descriptors::{FnDescriptor},
21 roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, 22 roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
22 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position, 23 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
@@ -143,10 +144,10 @@ impl AnalysisImpl {
143 .unwrap() 144 .unwrap()
144 } 145 }
145 pub fn file_syntax(&self, file_id: FileId) -> File { 146 pub fn file_syntax(&self, file_id: FileId) -> File {
146 self.root(file_id).syntax(file_id) 147 self.root(file_id).db().file_syntax(file_id)
147 } 148 }
148 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 149 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
149 self.root(file_id).lines(file_id) 150 self.root(file_id).db().file_lines(file_id)
150 } 151 }
151 pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { 152 pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
152 let mut buf = Vec::new(); 153 let mut buf = Vec::new();
@@ -161,14 +162,14 @@ impl AnalysisImpl {
161 } 162 }
162 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { 163 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
163 let root = self.root(file_id); 164 let root = self.root(file_id);
164 let module_tree = root.module_tree()?; 165 let module_tree = root.db().module_tree()?;
165 166
166 let res = module_tree.modules_for_file(file_id) 167 let res = module_tree.modules_for_file(file_id)
167 .into_iter() 168 .into_iter()
168 .filter_map(|module_id| { 169 .filter_map(|module_id| {
169 let link = module_id.parent_link(&module_tree)?; 170 let link = module_id.parent_link(&module_tree)?;
170 let file_id = link.owner(&module_tree).file_id(&module_tree); 171 let file_id = link.owner(&module_tree).file_id(&module_tree);
171 let syntax = root.syntax(file_id); 172 let syntax = root.db().file_syntax(file_id);
172 let decl = link.bind_source(&module_tree, syntax.ast()); 173 let decl = link.bind_source(&module_tree, syntax.ast());
173 174
174 let sym = FileSymbol { 175 let sym = FileSymbol {
@@ -182,7 +183,7 @@ impl AnalysisImpl {
182 Ok(res) 183 Ok(res)
183 } 184 }
184 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 185 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
185 let module_tree = self.root(file_id).module_tree()?; 186 let module_tree = self.root(file_id).db().module_tree()?;
186 let crate_graph = &self.data.crate_graph; 187 let crate_graph = &self.data.crate_graph;
187 let res = module_tree.modules_for_file(file_id) 188 let res = module_tree.modules_for_file(file_id)
188 .into_iter() 189 .into_iter()
@@ -202,8 +203,8 @@ impl AnalysisImpl {
202 offset: TextUnit, 203 offset: TextUnit,
203 ) -> Cancelable<Vec<(FileId, FileSymbol)>> { 204 ) -> Cancelable<Vec<(FileId, FileSymbol)>> {
204 let root = self.root(file_id); 205 let root = self.root(file_id);
205 let module_tree = root.module_tree()?; 206 let module_tree = root.db().module_tree()?;
206 let file = root.syntax(file_id); 207 let file = root.db().file_syntax(file_id);
207 let syntax = file.syntax(); 208 let syntax = file.syntax();
208 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { 209 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
209 // First try to resolve the symbol locally 210 // First try to resolve the symbol locally
@@ -253,7 +254,7 @@ impl AnalysisImpl {
253 254
254 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> { 255 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> {
255 let root = self.root(file_id); 256 let root = self.root(file_id);
256 let file = root.syntax(file_id); 257 let file = root.db().file_syntax(file_id);
257 let syntax = file.syntax(); 258 let syntax = file.syntax();
258 259
259 let mut ret = vec![]; 260 let mut ret = vec![];
@@ -285,8 +286,8 @@ impl AnalysisImpl {
285 286
286 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 287 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
287 let root = self.root(file_id); 288 let root = self.root(file_id);
288 let module_tree = root.module_tree()?; 289 let module_tree = root.db().module_tree()?;
289 let syntax = root.syntax(file_id); 290 let syntax = root.db().file_syntax(file_id);
290 291
291 let mut res = ra_editor::diagnostics(&syntax) 292 let mut res = ra_editor::diagnostics(&syntax)
292 .into_iter() 293 .into_iter()
@@ -376,7 +377,7 @@ impl AnalysisImpl {
376 offset: TextUnit, 377 offset: TextUnit,
377 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { 378 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
378 let root = self.root(file_id); 379 let root = self.root(file_id);
379 let file = root.syntax(file_id); 380 let file = root.db().file_syntax(file_id);
380 let syntax = file.syntax(); 381 let syntax = file.syntax();
381 382
382 // Find the calling expression and it's NameRef 383 // Find the calling expression and it's NameRef
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index a03f44205..67a239a5c 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -1,8 +1,4 @@
1extern crate parking_lot;
2#[macro_use]
3extern crate log;
4extern crate fst; 1extern crate fst;
5extern crate once_cell;
6extern crate ra_editor; 2extern crate ra_editor;
7extern crate ra_syntax; 3extern crate ra_syntax;
8extern crate rayon; 4extern crate rayon;
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs
index 15081f555..aa0243720 100644
--- a/crates/ra_analysis/src/roots.rs
+++ b/crates/ra_analysis/src/roots.rs
@@ -17,9 +17,7 @@ use crate::{
17 17
18pub(crate) trait SourceRoot { 18pub(crate) trait SourceRoot {
19 fn contains(&self, file_id: FileId) -> bool; 19 fn contains(&self, file_id: FileId) -> bool;
20 fn module_tree(&self) -> Cancelable<Arc<ModuleTree>>; 20 fn db(&self) -> &db::RootDatabase;
21 fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
22 fn syntax(&self, file_id: FileId) -> File;
23 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>; 21 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>;
24} 22}
25 23
@@ -63,17 +61,11 @@ impl WritableSourceRoot {
63} 61}
64 62
65impl SourceRoot for WritableSourceRoot { 63impl SourceRoot for WritableSourceRoot {
66 fn module_tree(&self) -> Cancelable<Arc<ModuleTree>> {
67 self.db.module_tree()
68 }
69 fn contains(&self, file_id: FileId) -> bool { 64 fn contains(&self, file_id: FileId) -> bool {
70 self.db.file_set().files.contains(&file_id) 65 self.db.file_set().files.contains(&file_id)
71 } 66 }
72 fn lines(&self, file_id: FileId) -> Arc<LineIndex> { 67 fn db(&self) -> &db::RootDatabase {
73 self.db.file_lines(file_id) 68 &self.db
74 }
75 fn syntax(&self, file_id: FileId) -> File {
76 self.db.file_syntax(file_id)
77 } 69 }
78 fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> { 70 fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
79 for &file_id in self.db.file_set().files.iter() { 71 for &file_id in self.db.file_set().files.iter() {
@@ -114,17 +106,11 @@ impl ReadonlySourceRoot {
114} 106}
115 107
116impl SourceRoot for ReadonlySourceRoot { 108impl SourceRoot for ReadonlySourceRoot {
117 fn module_tree(&self) -> Cancelable<Arc<ModuleTree>> {
118 self.db.module_tree()
119 }
120 fn contains(&self, file_id: FileId) -> bool { 109 fn contains(&self, file_id: FileId) -> bool {
121 self.db.file_set().files.contains(&file_id) 110 self.db.file_set().files.contains(&file_id)
122 } 111 }
123 fn lines(&self, file_id: FileId) -> Arc<LineIndex> { 112 fn db(&self) -> &db::RootDatabase {
124 self.db.file_lines(file_id) 113 &self.db
125 }
126 fn syntax(&self, file_id: FileId) -> File {
127 self.db.file_syntax(file_id)
128 } 114 }
129 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> { 115 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
130 acc.push(Arc::clone(&self.symbol_index)); 116 acc.push(Arc::clone(&self.symbol_index));