diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-15 08:38:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-15 08:38:08 +0000 |
commit | 65e31a1b5bc8879fce0acd0ea8941f33148c7804 (patch) | |
tree | 0e9459d34cd984d06f99ca21512eaa09d0cab73f /crates/ide_db/src/search.rs | |
parent | 67e299f9cf5807e92cf1e398511a5d5377f9dd84 (diff) | |
parent | 36a9daac70fe99d837ff3f5b2fb89d226423c1ba (diff) |
Merge #6875
6875: Add find usages for enum constructors r=matklad a=sasurau4
Fix #2549 for enum
Co-authored-by: Daiki Ihara <[email protected]>
Diffstat (limited to 'crates/ide_db/src/search.rs')
-rw-r--r-- | crates/ide_db/src/search.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 607185ca9..3936c7390 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -32,6 +32,7 @@ pub enum ReferenceKind { | |||
32 | StructLiteral, | 32 | StructLiteral, |
33 | RecordFieldExprOrPat, | 33 | RecordFieldExprOrPat, |
34 | SelfKw, | 34 | SelfKw, |
35 | EnumLiteral, | ||
35 | Other, | 36 | Other, |
36 | } | 37 | } |
37 | 38 | ||
@@ -284,6 +285,8 @@ impl<'a> FindUsages<'a> { | |||
284 | ReferenceKind::RecordFieldExprOrPat | 285 | ReferenceKind::RecordFieldExprOrPat |
285 | } else if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) { | 286 | } else if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) { |
286 | ReferenceKind::StructLiteral | 287 | ReferenceKind::StructLiteral |
288 | } else if is_enum_lit_name_ref(&name_ref) { | ||
289 | ReferenceKind::EnumLiteral | ||
287 | } else { | 290 | } else { |
288 | ReferenceKind::Other | 291 | ReferenceKind::Other |
289 | }; | 292 | }; |
@@ -402,3 +405,15 @@ fn is_record_field_expr_or_pat(name_ref: &ast::NameRef) -> bool { | |||
402 | false | 405 | false |
403 | } | 406 | } |
404 | } | 407 | } |
408 | |||
409 | fn is_enum_lit_name_ref(name_ref: &ast::NameRef) -> bool { | ||
410 | name_ref | ||
411 | .syntax() | ||
412 | .ancestors() | ||
413 | .find_map(ast::PathExpr::cast) | ||
414 | .and_then(|p| p.path()) | ||
415 | .and_then(|p| p.qualifier()) | ||
416 | .and_then(|p| p.segment()) | ||
417 | .map(|p| p.name_ref().as_ref() == Some(name_ref)) | ||
418 | .unwrap_or(false) | ||
419 | } | ||