aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/imp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r--crates/ra_analysis/src/imp.rs46
1 files changed, 28 insertions, 18 deletions
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;