From 45fce9034909f2f0c5f6ac70eca7cf87ec3db856 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 Dec 2018 22:46:23 +0300 Subject: ModuleSource is ItemSource --- crates/ra_analysis/src/imp.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index f5cb3550e..942b5b945 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -190,10 +190,7 @@ impl AnalysisImpl { Some(it) => it, }; let root = descr.crate_root(); - let file_id = root - .source() - .as_file() - .expect("root module always has a file as a source"); + let file_id = root.source().file_id(); let crate_graph = self.db.crate_graph(); let crate_id = crate_graph.crate_id_for_crate_root(file_id); -- cgit v1.2.3 From d8b0379e1063941331253905795699a918233ef9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 Dec 2018 23:44:00 +0300 Subject: Add functions to DefId --- .../src/completion/reference_completion.rs | 2 +- crates/ra_analysis/src/db.rs | 9 +---- crates/ra_analysis/src/imp.rs | 41 ++++++++++++++-------- crates/ra_analysis/src/lib.rs | 2 +- 4 files changed, 30 insertions(+), 24 deletions(-) (limited to 'crates/ra_analysis/src') 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( }; let target_module = match def_id.resolve(db)? { Def::Module(it) => it, - Def::Item => return Ok(()), + _ => return Ok(()), }; let module_scope = target_module.scope(db)?; 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 @@ use std::sync::Arc; use salsa::{self, Database}; use ra_db::{LocationIntener, BaseDatabase}; -use hir::{self, DefId, DefLoc, FnId, SourceItemId}; +use hir::{self, DefId, DefLoc}; use crate::{ symbol_index, @@ -15,7 +15,6 @@ pub(crate) struct RootDatabase { #[derive(Debug, Default)] struct IdMaps { - fns: LocationIntener, defs: LocationIntener, } @@ -58,12 +57,6 @@ impl AsRef> for RootDatabase { } } -impl AsRef> for RootDatabase { - fn as_ref(&self) -> &LocationIntener { - &self.id_maps.fns - } -} - salsa::database_storage! { pub(crate) struct RootDatabaseStorage for RootDatabase { 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 { let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, position.offset) { if let Some(fn_descr) = - hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref) + hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref)? { let scope = fn_descr.scope(&*self.db); // First try to resolve the symbol locally @@ -257,11 +257,11 @@ impl AnalysisImpl { Ok(vec![]) } - pub fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { + pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { let file = self.db.source_file(position.file_id); // Find the binding associated with the offset - let (binding, descr) = match find_binding(&self.db, &file, position) { - None => return Vec::new(), + let (binding, descr) = match find_binding(&self.db, &file, position)? { + None => return Ok(Vec::new()), Some(it) => it, }; @@ -274,25 +274,36 @@ impl AnalysisImpl { .map(|ref_desc| (position.file_id, ref_desc.range)), ); - return ret; + return Ok(ret); fn find_binding<'a>( db: &db::RootDatabase, source_file: &'a SourceFileNode, position: FilePosition, - ) -> Option<(ast::BindPat<'a>, hir::Function)> { + ) -> Cancelable, hir::Function)>> { let syntax = source_file.syntax(); if let Some(binding) = find_node_at_offset::(syntax, position.offset) { - let descr = hir::Function::guess_for_bind_pat(db, position.file_id, binding)?; - return Some((binding, descr)); + let descr = ctry!(hir::Function::guess_for_bind_pat( + db, + position.file_id, + binding + )?); + return Ok(Some((binding, descr))); }; - let name_ref = find_node_at_offset::(syntax, position.offset)?; - let descr = hir::Function::guess_for_name_ref(db, position.file_id, name_ref)?; + let name_ref = ctry!(find_node_at_offset::(syntax, position.offset)); + let descr = ctry!(hir::Function::guess_for_name_ref( + db, + position.file_id, + name_ref + )?); let scope = descr.scope(db); - let resolved = scope.resolve_local_name(name_ref)?; + let resolved = ctry!(scope.resolve_local_name(name_ref)); let resolved = resolved.ptr().resolve(source_file); - let binding = find_node_at_offset::(syntax, resolved.range().end())?; - Some((binding, descr)) + let binding = ctry!(find_node_at_offset::( + syntax, + resolved.range().end() + )); + Ok(Some((binding, descr))) } } @@ -408,7 +419,9 @@ impl AnalysisImpl { if fs.kind == FN_DEF { let fn_file = self.db.source_file(fn_file_id); if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { - let descr = hir::Function::guess_from_source(&*self.db, fn_file_id, fn_def); + let descr = ctry!(hir::Function::guess_from_source( + &*self.db, fn_file_id, fn_def + )?); if let Some(descriptor) = descr.signature_info(&*self.db) { // If we have a calling expression let's find which argument we are on 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 { self.imp.approximately_resolve_symbol(position) } pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { - Ok(self.imp.find_all_refs(position)) + self.imp.find_all_refs(position) } pub fn doc_comment_for( &self, -- cgit v1.2.3