Skip to content

Commit

Permalink
Merge pull request #18794 from 1hakusai1/fix_fill_match_arm_in_tokio_…
Browse files Browse the repository at this point in the history
…main

Fix bug of "fill match arm" action in tokio::main macro
  • Loading branch information
Veykril authored Dec 30, 2024
2 parents 8318875 + 9451d64 commit bd083d0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/ide-assists/src/handlers/add_missing_match_arms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(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);
}

Expand All @@ -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::Token(it) => {
// Don't have a way to make tokens mut, so instead make the parent mut
// and find the token again
let parent =
edit.make_syntax_mut(it.parent().expect("Token must have a 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)
// If a token is found, it is '{' or '}'
// The parent is `{ ... }`
let parent = it.parent().expect("Token must have a parent.");
syntax::SyntaxElement::from(edit.make_syntax_mut(parent))
}
}
};
Expand Down

0 comments on commit bd083d0

Please sign in to comment.