aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/references.rs49
1 files changed, 20 insertions, 29 deletions
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index c797918b0..ee065b6f9 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -127,6 +127,8 @@ pub(crate) fn find_refs_to_def(
127 def: &Definition, 127 def: &Definition,
128 search_scope: Option<SearchScope>, 128 search_scope: Option<SearchScope>,
129) -> Vec<Reference> { 129) -> Vec<Reference> {
130 let _p = profile("find_refs_to_def");
131
130 let search_scope = { 132 let search_scope = {
131 let base = SearchScope::for_def(&def, db); 133 let base = SearchScope::for_def(&def, db);
132 match search_scope { 134 match search_scope {
@@ -140,38 +142,10 @@ pub(crate) fn find_refs_to_def(
140 Some(it) => it.to_string(), 142 Some(it) => it.to_string(),
141 }; 143 };
142 144
143 process_definition(db, def, name, search_scope)
144}
145
146fn find_name(
147 sema: &Semantics<RootDatabase>,
148 syntax: &SyntaxNode,
149 position: FilePosition,
150 opt_name: Option<ast::Name>,
151) -> Option<RangeInfo<Definition>> {
152 if let Some(name) = opt_name {
153 let def = classify_name(sema, &name)?.definition();
154 let range = name.syntax().text_range();
155 return Some(RangeInfo::new(range, def));
156 }
157 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
158 let def = classify_name_ref(sema, &name_ref)?.definition();
159 let range = name_ref.syntax().text_range();
160 Some(RangeInfo::new(range, def))
161}
162
163fn process_definition(
164 db: &RootDatabase,
165 def: &Definition,
166 name: String,
167 scope: SearchScope,
168) -> Vec<Reference> {
169 let _p = profile("process_definition");
170
171 let pat = name.as_str(); 145 let pat = name.as_str();
172 let mut refs = vec![]; 146 let mut refs = vec![];
173 147
174 for (file_id, search_range) in scope { 148 for (file_id, search_range) in search_scope {
175 let text = db.file_text(file_id); 149 let text = db.file_text(file_id);
176 let search_range = 150 let search_range =
177 search_range.unwrap_or(TextRange::offset_len(0.into(), TextUnit::of_str(&text))); 151 search_range.unwrap_or(TextRange::offset_len(0.into(), TextUnit::of_str(&text)));
@@ -226,6 +200,23 @@ fn process_definition(
226 refs 200 refs
227} 201}
228 202
203fn find_name(
204 sema: &Semantics<RootDatabase>,
205 syntax: &SyntaxNode,
206 position: FilePosition,
207 opt_name: Option<ast::Name>,
208) -> Option<RangeInfo<Definition>> {
209 if let Some(name) = opt_name {
210 let def = classify_name(sema, &name)?.definition();
211 let range = name.syntax().text_range();
212 return Some(RangeInfo::new(range, def));
213 }
214 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
215 let def = classify_name_ref(sema, &name_ref)?.definition();
216 let range = name_ref.syntax().text_range();
217 Some(RangeInfo::new(range, def))
218}
219
229fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option<ReferenceAccess> { 220fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option<ReferenceAccess> {
230 match def { 221 match def {
231 Definition::Local(_) | Definition::StructField(_) => {} 222 Definition::Local(_) | Definition::StructField(_) => {}