mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 03:45:04 +00:00
Fix bug of "fill match arm" action in tokio::main macro
https://github.com/rust-lang/rust-analyzer/issues/18027
This commit is contained in:
parent
59bc7b49d0
commit
9451d64315
1 changed files with 7 additions and 9 deletions
|
@ -261,7 +261,9 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cap) = ctx.config.snippet_cap {
|
if let Some(cap) = ctx.config.snippet_cap {
|
||||||
if let Some(it) = first_new_arm.and_then(|arm| arm.syntax().descendants().find_map(ast::WildcardPat::cast)) {
|
if let Some(it) = first_new_arm
|
||||||
|
.and_then(|arm| arm.syntax().descendants().find_map(ast::WildcardPat::cast))
|
||||||
|
{
|
||||||
edit.add_placeholder_snippet(cap, it);
|
edit.add_placeholder_snippet(cap, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,14 +289,10 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
syntax::SyntaxElement::from(edit.make_syntax_mut(it))
|
syntax::SyntaxElement::from(edit.make_syntax_mut(it))
|
||||||
}
|
}
|
||||||
syntax::SyntaxElement::Token(it) => {
|
syntax::SyntaxElement::Token(it) => {
|
||||||
// Don't have a way to make tokens mut, so instead make the parent mut
|
// If a token is found, it is '{' or '}'
|
||||||
// and find the token again
|
// The parent is `{ ... }`
|
||||||
let parent =
|
let parent = it.parent().expect("Token must have a parent.");
|
||||||
edit.make_syntax_mut(it.parent().expect("Token must have a parent."));
|
syntax::SyntaxElement::from(edit.make_syntax_mut(parent))
|
||||||
let mut_token =
|
|
||||||
parent.covering_element(it.text_range()).into_token().expect("Covering element cannot be found. Range may be beyond the current node's range");
|
|
||||||
|
|
||||||
syntax::SyntaxElement::from(mut_token)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue