diff options
Diffstat (limited to 'crates/ra_ide_db/src/search.rs')
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 6f198df04..9436a7562 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -17,7 +17,7 @@ use rustc_hash::FxHashMap; | |||
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | defs::{classify_name_ref, Definition}, | 20 | defs::{classify_name_ref, Definition, NameRefClass}, |
21 | RootDatabase, | 21 | RootDatabase, |
22 | }; | 22 | }; |
23 | 23 | ||
@@ -30,6 +30,7 @@ pub struct Reference { | |||
30 | 30 | ||
31 | #[derive(Debug, Clone, PartialEq)] | 31 | #[derive(Debug, Clone, PartialEq)] |
32 | pub enum ReferenceKind { | 32 | pub enum ReferenceKind { |
33 | StructFieldShorthand, | ||
33 | StructLiteral, | 34 | StructLiteral, |
34 | Other, | 35 | Other, |
35 | } | 36 | } |
@@ -237,9 +238,8 @@ impl Definition { | |||
237 | // FIXME: reuse sb | 238 | // FIXME: reuse sb |
238 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 | 239 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 |
239 | 240 | ||
240 | if let Some(d) = classify_name_ref(&sema, &name_ref) { | 241 | match (classify_name_ref(&sema, &name_ref), self) { |
241 | let d = d.definition(); | 242 | (Some(NameRefClass::Definition(def)), _) if &def == self => { |
242 | if &d == self { | ||
243 | let kind = if is_record_lit_name_ref(&name_ref) | 243 | let kind = if is_record_lit_name_ref(&name_ref) |
244 | || is_call_expr_name_ref(&name_ref) | 244 | || is_call_expr_name_ref(&name_ref) |
245 | { | 245 | { |
@@ -252,9 +252,21 @@ impl Definition { | |||
252 | refs.push(Reference { | 252 | refs.push(Reference { |
253 | file_range, | 253 | file_range, |
254 | kind, | 254 | kind, |
255 | access: reference_access(&d, &name_ref), | 255 | access: reference_access(&def, &name_ref), |
256 | }); | 256 | }); |
257 | } | 257 | } |
258 | ( | ||
259 | Some(NameRefClass::FieldShorthand { local, field: _ }), | ||
260 | Definition::StructField(_), | ||
261 | ) => { | ||
262 | let file_range = sema.original_range(name_ref.syntax()); | ||
263 | refs.push(Reference { | ||
264 | file_range: file_range, | ||
265 | kind: ReferenceKind::StructFieldShorthand, | ||
266 | access: reference_access(&Definition::Local(local), &name_ref), | ||
267 | }); | ||
268 | } | ||
269 | _ => {} // not a usage | ||
258 | } | 270 | } |
259 | } | 271 | } |
260 | } | 272 | } |