From bd264031309fa2abc89851f95ca5cba6d15181cc Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Thu, 18 Jan 2024 17:43:15 +0800 Subject: [PATCH] fix panic with reference in macro --- .../src/handlers/extract_struct_from_enum_variant.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs index 65e2a018477..4961e05e2f7 100644 --- a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs @@ -412,6 +412,14 @@ fn reference_to_node( ) -> Option<(ast::PathSegment, SyntaxNode, hir::Module)> { let segment = reference.name.as_name_ref()?.syntax().parent().and_then(ast::PathSegment::cast)?; + + // filter out the reference in marco + let s_range = segment.syntax().text_range(); + let origin_range = sema.original_range(segment.syntax()).range; + if s_range != origin_range { + return None; + } + let parent = segment.parent_path().syntax().parent()?; let expr_or_pat = match_ast! { match parent {