Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-assists/src/utils.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs
index 676937c816..c7a6c2d532 100644
--- a/crates/ide-assists/src/utils.rs
+++ b/crates/ide-assists/src/utils.rs
@@ -1155,17 +1155,12 @@ pub(crate) fn get_struct_definition_from_context(
) -> Option<Either<ast::Struct, ast::Variant>> {
ctx.find_node_at_offset::<ast::Name>()
.and_then(|name| name.syntax().parent())
- .or(find_struct_keyword(ctx).and_then(|kw| kw.parent()))
+ .or(ctx
+ .token_at_offset()
+ .find(|leaf| matches!(leaf.kind(), STRUCT_KW))
+ .and_then(|kw| kw.parent()))
.or(ctx
.find_node_at_offset::<ast::Visibility>()
.and_then(|visibility| visibility.syntax().parent()))
.and_then(<Either<ast::Struct, ast::Variant>>::cast)
}
-
-fn find_struct_keyword(ctx: &AssistContext<'_>) -> Option<SyntaxToken> {
- // Attempt to find the token at the current cursor offset
- ctx.token_at_offset().find(|leaf| match leaf.kind() {
- STRUCT_KW => true,
- _ => false,
- })
-}