diff options
Diffstat (limited to 'crates/ide_db/src/search.rs')
-rw-r--r-- | crates/ide_db/src/search.rs | 63 |
1 files changed, 50 insertions, 13 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 3936c7390..525c8a41f 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -33,6 +33,7 @@ pub enum ReferenceKind { | |||
33 | RecordFieldExprOrPat, | 33 | RecordFieldExprOrPat, |
34 | SelfKw, | 34 | SelfKw, |
35 | EnumLiteral, | 35 | EnumLiteral, |
36 | Lifetime, | ||
36 | Other, | 37 | Other, |
37 | } | 38 | } |
38 | 39 | ||
@@ -129,6 +130,25 @@ impl Definition { | |||
129 | return SearchScope::new(res); | 130 | return SearchScope::new(res); |
130 | } | 131 | } |
131 | 132 | ||
133 | if let Definition::LifetimeParam(param) = self { | ||
134 | let range = match param.parent(db) { | ||
135 | hir::GenericDef::Function(it) => it.source(db).value.syntax().text_range(), | ||
136 | hir::GenericDef::Adt(it) => match it { | ||
137 | hir::Adt::Struct(it) => it.source(db).value.syntax().text_range(), | ||
138 | hir::Adt::Union(it) => it.source(db).value.syntax().text_range(), | ||
139 | hir::Adt::Enum(it) => it.source(db).value.syntax().text_range(), | ||
140 | }, | ||
141 | hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(), | ||
142 | hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(), | ||
143 | hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(), | ||
144 | hir::GenericDef::EnumVariant(it) => it.source(db).value.syntax().text_range(), | ||
145 | hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(), | ||
146 | }; | ||
147 | let mut res = FxHashMap::default(); | ||
148 | res.insert(file_id, Some(range)); | ||
149 | return SearchScope::new(res); | ||
150 | } | ||
151 | |||
132 | let vis = self.visibility(db); | 152 | let vis = self.visibility(db); |
133 | 153 | ||
134 | if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) { | 154 | if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) { |
@@ -255,25 +275,42 @@ impl<'a> FindUsages<'a> { | |||
255 | continue; | 275 | continue; |
256 | } | 276 | } |
257 | 277 | ||
258 | match sema.find_node_at_offset_with_descend(&tree, offset) { | 278 | if let Some(name_ref) = sema.find_node_at_offset_with_descend(&tree, offset) { |
259 | Some(name_ref) => { | 279 | if self.found_name_ref(&name_ref, sink) { |
260 | if self.found_name_ref(&name_ref, sink) { | 280 | return; |
261 | return; | 281 | } |
262 | } | 282 | } else if let Some(name) = sema.find_node_at_offset_with_descend(&tree, offset) { |
283 | if self.found_name(&name, sink) { | ||
284 | return; | ||
285 | } | ||
286 | } else if let Some(lifetime) = sema.find_node_at_offset_with_descend(&tree, offset) | ||
287 | { | ||
288 | if self.found_lifetime(&lifetime, sink) { | ||
289 | return; | ||
263 | } | 290 | } |
264 | None => match sema.find_node_at_offset_with_descend(&tree, offset) { | ||
265 | Some(name) => { | ||
266 | if self.found_name(&name, sink) { | ||
267 | return; | ||
268 | } | ||
269 | } | ||
270 | None => {} | ||
271 | }, | ||
272 | } | 291 | } |
273 | } | 292 | } |
274 | } | 293 | } |
275 | } | 294 | } |
276 | 295 | ||
296 | fn found_lifetime( | ||
297 | &self, | ||
298 | lifetime: &ast::Lifetime, | ||
299 | sink: &mut dyn FnMut(Reference) -> bool, | ||
300 | ) -> bool { | ||
301 | match NameRefClass::classify_lifetime(self.sema, lifetime) { | ||
302 | Some(NameRefClass::Definition(def)) if &def == self.def => { | ||
303 | let reference = Reference { | ||
304 | file_range: self.sema.original_range(lifetime.syntax()), | ||
305 | kind: ReferenceKind::Lifetime, | ||
306 | access: None, | ||
307 | }; | ||
308 | sink(reference) | ||
309 | } | ||
310 | _ => false, // not a usage | ||
311 | } | ||
312 | } | ||
313 | |||
277 | fn found_name_ref( | 314 | fn found_name_ref( |
278 | &self, | 315 | &self, |
279 | name_ref: &ast::NameRef, | 316 | name_ref: &ast::NameRef, |