aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/mod.rs')
-rw-r--r--crates/ra_analysis/src/descriptors/mod.rs39
1 files changed, 17 insertions, 22 deletions
diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs
index e27f8314a..c28764336 100644
--- a/crates/ra_analysis/src/descriptors/mod.rs
+++ b/crates/ra_analysis/src/descriptors/mod.rs
@@ -1,24 +1,22 @@
1pub(crate) mod module;
2pub(crate) mod function; 1pub(crate) mod function;
2pub(crate) mod module;
3 3
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use ra_syntax::{ 6use ra_syntax::{
7 SmolStr,
8 ast::{self, AstNode, FnDefNode}, 7 ast::{self, AstNode, FnDefNode},
9 TextRange 8 SmolStr, TextRange,
10}; 9};
11 10
12use crate::{ 11use crate::{
13 FileId, Cancelable,
14 db::SyntaxDatabase, 12 db::SyntaxDatabase,
15 descriptors::module::{ModuleTree, ModuleId, ModuleScope}, 13 descriptors::function::{resolve_local_name, FnId, FnScopes},
16 descriptors::function::{FnId, FnScopes, resolve_local_name}, 14 descriptors::module::{ModuleId, ModuleScope, ModuleTree},
17 input::SourceRootId, 15 input::SourceRootId,
18 syntax_ptr::{SyntaxPtrDatabase, LocalSyntaxPtr}, 16 syntax_ptr::{LocalSyntaxPtr, SyntaxPtrDatabase},
17 Cancelable, FileId,
19}; 18};
20 19
21
22salsa::query_group! { 20salsa::query_group! {
23 pub(crate) trait DescriptorDatabase: SyntaxDatabase + SyntaxPtrDatabase { 21 pub(crate) trait DescriptorDatabase: SyntaxDatabase + SyntaxPtrDatabase {
24 fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> { 22 fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
@@ -49,23 +47,20 @@ salsa::query_group! {
49#[derive(Debug)] 47#[derive(Debug)]
50pub struct ReferenceDescriptor { 48pub struct ReferenceDescriptor {
51 pub range: TextRange, 49 pub range: TextRange,
52 pub name: String 50 pub name: String,
53} 51}
54 52
55#[derive(Debug)] 53#[derive(Debug)]
56pub struct DeclarationDescriptor<'a> { 54pub struct DeclarationDescriptor<'a> {
57 pat: ast::BindPat<'a>, 55 pat: ast::BindPat<'a>,
58 pub range: TextRange 56 pub range: TextRange,
59} 57}
60 58
61impl<'a> DeclarationDescriptor<'a> { 59impl<'a> DeclarationDescriptor<'a> {
62 pub fn new(pat: ast::BindPat) -> DeclarationDescriptor { 60 pub fn new(pat: ast::BindPat) -> DeclarationDescriptor {
63 let range = pat.syntax().range(); 61 let range = pat.syntax().range();
64 62
65 DeclarationDescriptor { 63 DeclarationDescriptor { pat, range }
66 pat,
67 range
68 }
69 } 64 }
70 65
71 pub fn find_all_refs(&self) -> Vec<ReferenceDescriptor> { 66 pub fn find_all_refs(&self) -> Vec<ReferenceDescriptor> {
@@ -73,22 +68,22 @@ impl<'a> DeclarationDescriptor<'a> {
73 68
74 let fn_def = match self.pat.syntax().ancestors().find_map(ast::FnDef::cast) { 69 let fn_def = match self.pat.syntax().ancestors().find_map(ast::FnDef::cast) {
75 Some(def) => def, 70 Some(def) => def,
76 None => return Default::default() 71 None => return Default::default(),
77 }; 72 };
78 73
79 let fn_scopes = FnScopes::new(fn_def); 74 let fn_scopes = FnScopes::new(fn_def);
80 75
81 let refs : Vec<_> = fn_def.syntax().descendants() 76 let refs: Vec<_> = fn_def
77 .syntax()
78 .descendants()
82 .filter_map(ast::NameRef::cast) 79 .filter_map(ast::NameRef::cast)
83 .filter(|name_ref| { 80 .filter(|name_ref| match resolve_local_name(*name_ref, &fn_scopes) {
84 match resolve_local_name(*name_ref, &fn_scopes) { 81 None => false,
85 None => false, 82 Some(entry) => entry.ptr() == name_ptr,
86 Some(entry) => entry.ptr() == name_ptr,
87 }
88 }) 83 })
89 .map(|name_ref| ReferenceDescriptor { 84 .map(|name_ref| ReferenceDescriptor {
90 name: name_ref.syntax().text().to_string(), 85 name: name_ref.syntax().text().to_string(),
91 range : name_ref.syntax().range(), 86 range: name_ref.syntax().range(),
92 }) 87 })
93 .collect(); 88 .collect();
94 89