aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/imp.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-31 20:41:43 +0000
committerAleksey Kladov <[email protected]>2018-10-31 20:41:43 +0000
commit6be50f7d5de3737464853a589673375fc0cafa97 (patch)
tree2c6da7f3a1234c3f2fd3f330d2c9445953979598 /crates/ra_analysis/src/imp.rs
parent857c1650efdb51650458f9ec1119adaa49b34371 (diff)
Reformat all
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r--crates/ra_analysis/src/imp.rs77
1 files changed, 42 insertions, 35 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 1eb8cb912..44077b507 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -13,24 +13,21 @@ use ra_syntax::{
13use rayon::prelude::*; 13use rayon::prelude::*;
14use relative_path::RelativePath; 14use relative_path::RelativePath;
15use rustc_hash::FxHashSet; 15use rustc_hash::FxHashSet;
16use salsa::{ParallelDatabase, Database}; 16use salsa::{Database, ParallelDatabase};
17 17
18use crate::{ 18use crate::{
19 AnalysisChange, 19 completion::{resolve_based_completion, scope_completion, CompletionItem},
20 db::{ 20 db::{self, FileSyntaxQuery, SyntaxDatabase},
21 self, SyntaxDatabase, FileSyntaxQuery,
22 },
23 input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE},
24 descriptors::{ 21 descriptors::{
25 DescriptorDatabase, DeclarationDescriptor,
26 module::{ModuleTree, Problem},
27 function::{FnDescriptor, FnId}, 22 function::{FnDescriptor, FnId},
23 module::{ModuleTree, Problem},
24 DeclarationDescriptor, DescriptorDatabase,
28 }, 25 },
29 completion::{scope_completion, resolve_based_completion, CompletionItem}, 26 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
30 symbol_index::SymbolIndex, 27 symbol_index::SymbolIndex,
31 syntax_ptr::SyntaxPtrDatabase, 28 syntax_ptr::SyntaxPtrDatabase,
32 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position, 29 AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
33 Query, SourceChange, SourceFileEdit, Cancelable, 30 FileSystemEdit, Position, Query, SourceChange, SourceFileEdit,
34}; 31};
35 32
36#[derive(Clone, Debug)] 33#[derive(Clone, Debug)]
@@ -94,7 +91,6 @@ pub(crate) struct AnalysisHostImpl {
94 db: db::RootDatabase, 91 db: db::RootDatabase,
95} 92}
96 93
97
98impl AnalysisHostImpl { 94impl AnalysisHostImpl {
99 pub fn new() -> AnalysisHostImpl { 95 pub fn new() -> AnalysisHostImpl {
100 let db = db::RootDatabase::default(); 96 let db = db::RootDatabase::default();
@@ -108,7 +104,7 @@ impl AnalysisHostImpl {
108 } 104 }
109 pub fn analysis(&self) -> AnalysisImpl { 105 pub fn analysis(&self) -> AnalysisImpl {
110 AnalysisImpl { 106 AnalysisImpl {
111 db: self.db.fork() // freeze revision here 107 db: self.db.fork(), // freeze revision here
112 } 108 }
113 } 109 }
114 pub fn apply_change(&mut self, change: AnalysisChange) { 110 pub fn apply_change(&mut self, change: AnalysisChange) {
@@ -120,7 +116,8 @@ impl AnalysisHostImpl {
120 .set(file_id, Arc::new(text)) 116 .set(file_id, Arc::new(text))
121 } 117 }
122 if !(change.files_added.is_empty() && change.files_removed.is_empty()) { 118 if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
123 let file_resolver = change.file_resolver 119 let file_resolver = change
120 .file_resolver
124 .expect("change resolver when changing set of files"); 121 .expect("change resolver when changing set of files");
125 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE)); 122 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
126 for (file_id, text) in change.files_added { 123 for (file_id, text) in change.files_added {
@@ -174,7 +171,8 @@ impl AnalysisHostImpl {
174 .set((), Arc::new(libraries)); 171 .set((), Arc::new(libraries));
175 } 172 }
176 if let Some(crate_graph) = change.crate_graph { 173 if let Some(crate_graph) = change.crate_graph {
177 self.db.query(crate::input::CrateGraphQuery) 174 self.db
175 .query(crate::input::CrateGraphQuery)
178 .set((), Arc::new(crate_graph)) 176 .set((), Arc::new(crate_graph))
179 } 177 }
180 } 178 }
@@ -194,18 +192,22 @@ impl AnalysisImpl {
194 } 192 }
195 pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { 193 pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
196 let buf: Vec<Arc<SymbolIndex>> = if query.libs { 194 let buf: Vec<Arc<SymbolIndex>> = if query.libs {
197 self.db.libraries().iter() 195 self.db
196 .libraries()
197 .iter()
198 .map(|&lib_id| self.db.library_symbols(lib_id)) 198 .map(|&lib_id| self.db.library_symbols(lib_id))
199 .collect() 199 .collect()
200 } else { 200 } else {
201 let files = &self.db.source_root(WORKSPACE).files; 201 let files = &self.db.source_root(WORKSPACE).files;
202 let db = self.db.clone(); 202 let db = self.db.clone();
203 files.par_iter() 203 files
204 .par_iter()
204 .map_with(db, |db, &file_id| db.file_symbols(file_id)) 205 .map_with(db, |db, &file_id| db.file_symbols(file_id))
205 .filter_map(|it| it.ok()) 206 .filter_map(|it| it.ok())
206 .collect() 207 .collect()
207 }; 208 };
208 self.db.query(FileSyntaxQuery) 209 self.db
210 .query(FileSyntaxQuery)
209 .sweep(salsa::SweepStrategy::default().discard_values()); 211 .sweep(salsa::SweepStrategy::default().discard_values());
210 Ok(query.search(&buf)) 212 Ok(query.search(&buf))
211 } 213 }
@@ -216,7 +218,8 @@ impl AnalysisImpl {
216 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { 218 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
217 let module_tree = self.module_tree(file_id)?; 219 let module_tree = self.module_tree(file_id)?;
218 220
219 let res = module_tree.modules_for_file(file_id) 221 let res = module_tree
222 .modules_for_file(file_id)
220 .into_iter() 223 .into_iter()
221 .filter_map(|module_id| { 224 .filter_map(|module_id| {
222 let link = module_id.parent_link(&module_tree)?; 225 let link = module_id.parent_link(&module_tree)?;
@@ -237,7 +240,8 @@ impl AnalysisImpl {
237 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 240 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
238 let module_tree = self.module_tree(file_id)?; 241 let module_tree = self.module_tree(file_id)?;
239 let crate_graph = self.db.crate_graph(); 242 let crate_graph = self.db.crate_graph();
240 let res = module_tree.modules_for_file(file_id) 243 let res = module_tree
244 .modules_for_file(file_id)
241 .into_iter() 245 .into_iter()
242 .map(|it| it.root(&module_tree)) 246 .map(|it| it.root(&module_tree))
243 .map(|it| it.file_id(&module_tree)) 247 .map(|it| it.file_id(&module_tree))
@@ -249,7 +253,11 @@ impl AnalysisImpl {
249 pub fn crate_root(&self, crate_id: CrateId) -> FileId { 253 pub fn crate_root(&self, crate_id: CrateId) -> FileId {
250 self.db.crate_graph().crate_roots[&crate_id] 254 self.db.crate_graph().crate_roots[&crate_id]
251 } 255 }
252 pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Cancelable<Option<Vec<CompletionItem>>> { 256 pub fn completions(
257 &self,
258 file_id: FileId,
259 offset: TextUnit,
260 ) -> Cancelable<Option<Vec<CompletionItem>>> {
253 let mut res = Vec::new(); 261 let mut res = Vec::new();
254 let mut has_completions = false; 262 let mut has_completions = false;
255 if let Some(scope_based) = scope_completion(&self.db, file_id, offset) { 263 if let Some(scope_based) = scope_completion(&self.db, file_id, offset) {
@@ -260,11 +268,7 @@ impl AnalysisImpl {
260 res.extend(scope_based); 268 res.extend(scope_based);
261 has_completions = true; 269 has_completions = true;
262 } 270 }
263 let res = if has_completions { 271 let res = if has_completions { Some(res) } else { None };
264 Some(res)
265 } else {
266 None
267 };
268 Ok(res) 272 Ok(res)
269 } 273 }
270 pub fn approximately_resolve_symbol( 274 pub fn approximately_resolve_symbol(
@@ -326,12 +330,11 @@ impl AnalysisImpl {
326 let syntax = file.syntax(); 330 let syntax = file.syntax();
327 331
328 // Find the binding associated with the offset 332 // Find the binding associated with the offset
329 let maybe_binding = find_node_at_offset::<ast::BindPat>(syntax, offset) 333 let maybe_binding = find_node_at_offset::<ast::BindPat>(syntax, offset).or_else(|| {
330 .or_else(|| { 334 let name_ref = find_node_at_offset::<ast::NameRef>(syntax, offset)?;
331 let name_ref = find_node_at_offset::<ast::NameRef>(syntax, offset)?; 335 let resolved = resolve_local_name(&self.db, file_id, name_ref)?;
332 let resolved = resolve_local_name(&self.db, file_id, name_ref)?; 336 find_node_at_offset::<ast::BindPat>(syntax, resolved.1.end())
333 find_node_at_offset::<ast::BindPat>(syntax, resolved.1.end()) 337 });
334 });
335 338
336 let binding = match maybe_binding { 339 let binding = match maybe_binding {
337 None => return Vec::new(), 340 None => return Vec::new(),
@@ -341,8 +344,11 @@ impl AnalysisImpl {
341 let decl = DeclarationDescriptor::new(binding); 344 let decl = DeclarationDescriptor::new(binding);
342 345
343 let mut ret = vec![(file_id, decl.range)]; 346 let mut ret = vec![(file_id, decl.range)];
344 ret.extend(decl.find_all_refs().into_iter() 347 ret.extend(
345 .map(|ref_desc| (file_id, ref_desc.range ))); 348 decl.find_all_refs()
349 .into_iter()
350 .map(|ref_desc| (file_id, ref_desc.range)),
351 );
346 352
347 ret 353 ret
348 } 354 }
@@ -526,7 +532,8 @@ impl AnalysisImpl {
526 Some(id) => id, 532 Some(id) => id,
527 None => return Vec::new(), 533 None => return Vec::new(),
528 }; 534 };
529 module_id.child(module_tree, name.as_str()) 535 module_id
536 .child(module_tree, name.as_str())
530 .map(|it| it.file_id(module_tree)) 537 .map(|it| it.file_id(module_tree))
531 .into_iter() 538 .into_iter()
532 .collect() 539 .collect()