aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-04 20:54:54 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-04 20:54:54 +0000
commit84f250973079508e52d81be88f45a401958442dd (patch)
treebe2864c8f1906f096e37e0778fa18524e2ddbe67 /crates/ra_analysis
parent244f9a142f0593ab5847163d1832e464e2524c4b (diff)
parent54d053c881514b024ba399ce2edc678e3f710ab7 (diff)
Merge #254
254: Defids r=matklad a=matklad Fleshing out DefIds some more Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs2
-rw-r--r--crates/ra_analysis/src/db.rs9
-rw-r--r--crates/ra_analysis/src/imp.rs46
-rw-r--r--crates/ra_analysis/src/lib.rs2
4 files changed, 31 insertions, 28 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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use salsa::{self, Database}; 2use salsa::{self, Database};
3use ra_db::{LocationIntener, BaseDatabase}; 3use ra_db::{LocationIntener, BaseDatabase};
4use hir::{self, DefId, DefLoc, FnId, SourceItemId}; 4use hir::{self, DefId, DefLoc};
5 5
6use crate::{ 6use 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)]
17struct IdMaps { 17struct 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
61impl AsRef<LocationIntener<hir::SourceItemId, FnId>> for RootDatabase {
62 fn as_ref(&self) -> &LocationIntener<hir::SourceItemId, FnId> {
63 &self.id_maps.fns
64 }
65}
66
67salsa::database_storage! { 60salsa::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 f5cb3550e..fe1dfefea 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -190,10 +190,7 @@ impl AnalysisImpl {
190 Some(it) => it, 190 Some(it) => it,
191 }; 191 };
192 let root = descr.crate_root(); 192 let root = descr.crate_root();
193 let file_id = root 193 let file_id = root.source().file_id();
194 .source()
195 .as_file()
196 .expect("root module always has a file as a source");
197 194
198 let crate_graph = self.db.crate_graph(); 195 let crate_graph = self.db.crate_graph();
199 let crate_id = crate_graph.crate_id_for_crate_root(file_id); 196 let crate_id = crate_graph.crate_id_for_crate_root(file_id);
@@ -213,7 +210,7 @@ impl AnalysisImpl {
213 let syntax = file.syntax(); 210 let syntax = file.syntax();
214 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) {
215 if let Some(fn_descr) = 212 if let Some(fn_descr) =
216 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)?
217 { 214 {
218 let scope = fn_descr.scope(&*self.db); 215 let scope = fn_descr.scope(&*self.db);
219 // First try to resolve the symbol locally 216 // First try to resolve the symbol locally
@@ -260,11 +257,11 @@ impl AnalysisImpl {
260 Ok(vec![]) 257 Ok(vec![])
261 } 258 }
262 259
263 pub fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { 260 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
264 let file = self.db.source_file(position.file_id); 261 let file = self.db.source_file(position.file_id);
265 // Find the binding associated with the offset 262 // Find the binding associated with the offset
266 let (binding, descr) = match find_binding(&self.db, &file, position) { 263 let (binding, descr) = match find_binding(&self.db, &file, position)? {
267 None => return Vec::new(), 264 None => return Ok(Vec::new()),
268 Some(it) => it, 265 Some(it) => it,
269 }; 266 };
270 267
@@ -277,25 +274,36 @@ impl AnalysisImpl {
277 .map(|ref_desc| (position.file_id, ref_desc.range)), 274 .map(|ref_desc| (position.file_id, ref_desc.range)),
278 ); 275 );
279 276
280 return ret; 277 return Ok(ret);
281 278
282 fn find_binding<'a>( 279 fn find_binding<'a>(
283 db: &db::RootDatabase, 280 db: &db::RootDatabase,
284 source_file: &'a SourceFileNode, 281 source_file: &'a SourceFileNode,
285 position: FilePosition, 282 position: FilePosition,
286 ) -> Option<(ast::BindPat<'a>, hir::Function)> { 283 ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> {
287 let syntax = source_file.syntax(); 284 let syntax = source_file.syntax();
288 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) {
289 let descr = hir::Function::guess_for_bind_pat(db, position.file_id, binding)?; 286 let descr = ctry!(hir::Function::guess_for_bind_pat(
290 return Some((binding, descr)); 287 db,
288 position.file_id,
289 binding
290 )?);
291 return Ok(Some((binding, descr)));
291 }; 292 };
292 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));
293 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 )?);
294 let scope = descr.scope(db); 299 let scope = descr.scope(db);
295 let resolved = scope.resolve_local_name(name_ref)?; 300 let resolved = ctry!(scope.resolve_local_name(name_ref));
296 let resolved = resolved.ptr().resolve(source_file); 301 let resolved = resolved.ptr().resolve(source_file);
297 let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?; 302 let binding = ctry!(find_node_at_offset::<ast::BindPat>(
298 Some((binding, descr)) 303 syntax,
304 resolved.range().end()
305 ));
306 Ok(Some((binding, descr)))
299 } 307 }
300 } 308 }
301 309
@@ -411,7 +419,9 @@ impl AnalysisImpl {
411 if fs.kind == FN_DEF { 419 if fs.kind == FN_DEF {
412 let fn_file = self.db.source_file(fn_file_id); 420 let fn_file = self.db.source_file(fn_file_id);
413 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()) {
414 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 )?);
415 if let Some(descriptor) = descr.signature_info(&*self.db) { 425 if let Some(descriptor) = descr.signature_info(&*self.db) {
416 // 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
417 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,