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