fix panic with reference in macro

This commit is contained in:
Young-Flash 2024-01-18 17:43:15 +08:00
parent ae6e737724
commit bd26403130

View file

@ -412,6 +412,14 @@ fn reference_to_node(
) -> Option<(ast::PathSegment, SyntaxNode, hir::Module)> { ) -> Option<(ast::PathSegment, SyntaxNode, hir::Module)> {
let segment = let segment =
reference.name.as_name_ref()?.syntax().parent().and_then(ast::PathSegment::cast)?; 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 parent = segment.parent_path().syntax().parent()?;
let expr_or_pat = match_ast! { let expr_or_pat = match_ast! {
match parent { match parent {