diff options
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/completion/reference_completion.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/db.rs | 9 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 41 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 2 |
4 files changed, 30 insertions, 24 deletions
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs index 8ea7478a8..f483ed045 100644 --- a/crates/ra_analysis/src/completion/reference_completion.rs +++ b/crates/ra_analysis/src/completion/reference_completion.rs | |||
@@ -163,7 +163,7 @@ fn complete_path( | |||
163 | }; | 163 | }; |
164 | let target_module = match def_id.resolve(db)? { | 164 | let target_module = match def_id.resolve(db)? { |
165 | Def::Module(it) => it, | 165 | Def::Module(it) => it, |
166 | Def::Item => return Ok(()), | 166 | _ => return Ok(()), |
167 | }; | 167 | }; |
168 | let module_scope = target_module.scope(db)?; | 168 | let module_scope = target_module.scope(db)?; |
169 | let completions = module_scope.entries().map(|(name, _res)| CompletionItem { | 169 | let completions = module_scope.entries().map(|(name, _res)| CompletionItem { |
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index df2ef293d..b8d774eb5 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use salsa::{self, Database}; | 2 | use salsa::{self, Database}; |
3 | use ra_db::{LocationIntener, BaseDatabase}; | 3 | use ra_db::{LocationIntener, BaseDatabase}; |
4 | use hir::{self, DefId, DefLoc, FnId, SourceItemId}; | 4 | use hir::{self, DefId, DefLoc}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | symbol_index, | 7 | symbol_index, |
@@ -15,7 +15,6 @@ pub(crate) struct RootDatabase { | |||
15 | 15 | ||
16 | #[derive(Debug, Default)] | 16 | #[derive(Debug, Default)] |
17 | struct IdMaps { | 17 | struct IdMaps { |
18 | fns: LocationIntener<SourceItemId, FnId>, | ||
19 | defs: LocationIntener<DefLoc, DefId>, | 18 | defs: LocationIntener<DefLoc, DefId>, |
20 | } | 19 | } |
21 | 20 | ||
@@ -58,12 +57,6 @@ impl AsRef<LocationIntener<DefLoc, DefId>> for RootDatabase { | |||
58 | } | 57 | } |
59 | } | 58 | } |
60 | 59 | ||
61 | impl AsRef<LocationIntener<hir::SourceItemId, FnId>> for RootDatabase { | ||
62 | fn as_ref(&self) -> &LocationIntener<hir::SourceItemId, FnId> { | ||
63 | &self.id_maps.fns | ||
64 | } | ||
65 | } | ||
66 | |||
67 | salsa::database_storage! { | 60 | salsa::database_storage! { |
68 | pub(crate) struct RootDatabaseStorage for RootDatabase { | 61 | pub(crate) struct RootDatabaseStorage for RootDatabase { |
69 | impl ra_db::FilesDatabase { | 62 | impl ra_db::FilesDatabase { |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 942b5b945..fe1dfefea 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -210,7 +210,7 @@ impl AnalysisImpl { | |||
210 | let syntax = file.syntax(); | 210 | let syntax = file.syntax(); |
211 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 211 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
212 | if let Some(fn_descr) = | 212 | if let Some(fn_descr) = |
213 | hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref) | 213 | hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref)? |
214 | { | 214 | { |
215 | let scope = fn_descr.scope(&*self.db); | 215 | let scope = fn_descr.scope(&*self.db); |
216 | // First try to resolve the symbol locally | 216 | // First try to resolve the symbol locally |
@@ -257,11 +257,11 @@ impl AnalysisImpl { | |||
257 | Ok(vec![]) | 257 | Ok(vec![]) |
258 | } | 258 | } |
259 | 259 | ||
260 | pub fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { | 260 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
261 | let file = self.db.source_file(position.file_id); | 261 | let file = self.db.source_file(position.file_id); |
262 | // Find the binding associated with the offset | 262 | // Find the binding associated with the offset |
263 | let (binding, descr) = match find_binding(&self.db, &file, position) { | 263 | let (binding, descr) = match find_binding(&self.db, &file, position)? { |
264 | None => return Vec::new(), | 264 | None => return Ok(Vec::new()), |
265 | Some(it) => it, | 265 | Some(it) => it, |
266 | }; | 266 | }; |
267 | 267 | ||
@@ -274,25 +274,36 @@ impl AnalysisImpl { | |||
274 | .map(|ref_desc| (position.file_id, ref_desc.range)), | 274 | .map(|ref_desc| (position.file_id, ref_desc.range)), |
275 | ); | 275 | ); |
276 | 276 | ||
277 | return ret; | 277 | return Ok(ret); |
278 | 278 | ||
279 | fn find_binding<'a>( | 279 | fn find_binding<'a>( |
280 | db: &db::RootDatabase, | 280 | db: &db::RootDatabase, |
281 | source_file: &'a SourceFileNode, | 281 | source_file: &'a SourceFileNode, |
282 | position: FilePosition, | 282 | position: FilePosition, |
283 | ) -> Option<(ast::BindPat<'a>, hir::Function)> { | 283 | ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { |
284 | let syntax = source_file.syntax(); | 284 | let syntax = source_file.syntax(); |
285 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | 285 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { |
286 | let descr = hir::Function::guess_for_bind_pat(db, position.file_id, binding)?; | 286 | let descr = ctry!(hir::Function::guess_for_bind_pat( |
287 | return Some((binding, descr)); | 287 | db, |
288 | position.file_id, | ||
289 | binding | ||
290 | )?); | ||
291 | return Ok(Some((binding, descr))); | ||
288 | }; | 292 | }; |
289 | let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?; | 293 | let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); |
290 | let descr = hir::Function::guess_for_name_ref(db, position.file_id, name_ref)?; | 294 | let descr = ctry!(hir::Function::guess_for_name_ref( |
295 | db, | ||
296 | position.file_id, | ||
297 | name_ref | ||
298 | )?); | ||
291 | let scope = descr.scope(db); | 299 | let scope = descr.scope(db); |
292 | let resolved = scope.resolve_local_name(name_ref)?; | 300 | let resolved = ctry!(scope.resolve_local_name(name_ref)); |
293 | let resolved = resolved.ptr().resolve(source_file); | 301 | let resolved = resolved.ptr().resolve(source_file); |
294 | let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?; | 302 | let binding = ctry!(find_node_at_offset::<ast::BindPat>( |
295 | Some((binding, descr)) | 303 | syntax, |
304 | resolved.range().end() | ||
305 | )); | ||
306 | Ok(Some((binding, descr))) | ||
296 | } | 307 | } |
297 | } | 308 | } |
298 | 309 | ||
@@ -408,7 +419,9 @@ impl AnalysisImpl { | |||
408 | if fs.kind == FN_DEF { | 419 | if fs.kind == FN_DEF { |
409 | let fn_file = self.db.source_file(fn_file_id); | 420 | let fn_file = self.db.source_file(fn_file_id); |
410 | if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { | 421 | if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { |
411 | let descr = hir::Function::guess_from_source(&*self.db, fn_file_id, fn_def); | 422 | let descr = ctry!(hir::Function::guess_from_source( |
423 | &*self.db, fn_file_id, fn_def | ||
424 | )?); | ||
412 | if let Some(descriptor) = descr.signature_info(&*self.db) { | 425 | if let Some(descriptor) = descr.signature_info(&*self.db) { |
413 | // If we have a calling expression let's find which argument we are on | 426 | // If we have a calling expression let's find which argument we are on |
414 | let mut current_parameter = None; | 427 | let mut current_parameter = None; |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 12df580ba..90528edfd 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -248,7 +248,7 @@ impl Analysis { | |||
248 | self.imp.approximately_resolve_symbol(position) | 248 | self.imp.approximately_resolve_symbol(position) |
249 | } | 249 | } |
250 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 250 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
251 | Ok(self.imp.find_all_refs(position)) | 251 | self.imp.find_all_refs(position) |
252 | } | 252 | } |
253 | pub fn doc_comment_for( | 253 | pub fn doc_comment_for( |
254 | &self, | 254 | &self, |