aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-11-14 18:57:47 +0000
committerLukas Wirth <[email protected]>2020-11-14 20:08:20 +0000
commitcb60708274dc7c8cff281364507d23047cd482cd (patch)
tree31ebdff3546086e3d0c784535ceaad1ed945cb8b /crates/ide_db/src
parent924eecf4af4d57c597c2e77c5e58c22b2a37bdb6 (diff)
Use shorthand field syntax in destructures
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/search.rs32
1 files changed, 22 insertions, 10 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 4248606c8..a3e765d05 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -30,7 +30,7 @@ pub enum ReferenceKind {
30 FieldShorthandForField, 30 FieldShorthandForField,
31 FieldShorthandForLocal, 31 FieldShorthandForLocal,
32 StructLiteral, 32 StructLiteral,
33 RecordExprField, 33 RecordFieldExprOrPat,
34 Other, 34 Other,
35} 35}
36 36
@@ -279,15 +279,13 @@ impl<'a> FindUsages<'a> {
279 ) -> bool { 279 ) -> bool {
280 match NameRefClass::classify(self.sema, &name_ref) { 280 match NameRefClass::classify(self.sema, &name_ref) {
281 Some(NameRefClass::Definition(def)) if &def == self.def => { 281 Some(NameRefClass::Definition(def)) if &def == self.def => {
282 let kind = 282 let kind = if is_record_field_expr_or_pat(&name_ref) {
283 if name_ref.syntax().parent().and_then(ast::RecordExprField::cast).is_some() { 283 ReferenceKind::RecordFieldExprOrPat
284 ReferenceKind::RecordExprField 284 } else if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) {
285 } else if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) 285 ReferenceKind::StructLiteral
286 { 286 } else {
287 ReferenceKind::StructLiteral 287 ReferenceKind::Other
288 } else { 288 };
289 ReferenceKind::Other
290 };
291 289
292 let reference = Reference { 290 let reference = Reference {
293 file_range: self.sema.original_range(name_ref.syntax()), 291 file_range: self.sema.original_range(name_ref.syntax()),
@@ -389,3 +387,17 @@ fn is_record_lit_name_ref(name_ref: &ast::NameRef) -> bool {
389 .map(|p| p.name_ref().as_ref() == Some(name_ref)) 387 .map(|p| p.name_ref().as_ref() == Some(name_ref))
390 .unwrap_or(false) 388 .unwrap_or(false)
391} 389}
390
391fn is_record_field_expr_or_pat(name_ref: &ast::NameRef) -> bool {
392 if let Some(parent) = name_ref.syntax().parent() {
393 match_ast! {
394 match parent {
395 ast::RecordExprField(it) => true,
396 ast::RecordPatField(_it) => true,
397 _ => false,
398 }
399 }
400 } else {
401 false
402 }
403}