From 36a9daac70fe99d837ff3f5b2fb89d226423c1ba Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Tue, 15 Dec 2020 00:39:42 +0900 Subject: Add find usages for enum constructors --- crates/ide_db/src/search.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ide_db/src') 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 { StructLiteral, RecordFieldExprOrPat, SelfKw, + EnumLiteral, Other, } @@ -284,6 +285,8 @@ impl<'a> FindUsages<'a> { ReferenceKind::RecordFieldExprOrPat } else if is_record_lit_name_ref(&name_ref) || is_call_expr_name_ref(&name_ref) { ReferenceKind::StructLiteral + } else if is_enum_lit_name_ref(&name_ref) { + ReferenceKind::EnumLiteral } else { ReferenceKind::Other }; @@ -402,3 +405,15 @@ fn is_record_field_expr_or_pat(name_ref: &ast::NameRef) -> bool { false } } + +fn is_enum_lit_name_ref(name_ref: &ast::NameRef) -> bool { + name_ref + .syntax() + .ancestors() + .find_map(ast::PathExpr::cast) + .and_then(|p| p.path()) + .and_then(|p| p.qualifier()) + .and_then(|p| p.segment()) + .map(|p| p.name_ref().as_ref() == Some(name_ref)) + .unwrap_or(false) +} -- cgit v1.2.3