-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add "Remove else branches" assist
#19918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| .and_then(|if_expr| if_expr.else_branch()?.syntax().clone().into()) | ||
| .or_else(|| { | ||
| ctx.find_node_at_range::<ast::LetStmt>()? | ||
| .let_else()? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be triggered on let else statements? I think most let else statements' else branch is not unreachable and removing them will result in compilation errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be used for operations after refactoring into irrefutable pattern
Veykril
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can combine this with the unwrap block assist which has a similar purpose?
I don't quite understand, what should I do? |
|
We have this unwrap block assist here https://github.com/rust-analyzer/rust-analyzer/blob/c5181dbbe33af6f21b9d83e02fdb6fda298a3b65/crates/ide-assists/src/handlers/unwrap_block.rs which I just realized already does what this assist does I believe? If you put the cursor on the else block's braces it pops up there Though it does not trigger for let else yet |
If it is applicable to For example: let Some(x) = val else {$0 return false; };Possible output one: return false;This seems niche enough Possible output two: let Some(x) = val;This does not match the name of the unwrap block
Do I need to trigger |
|
Ah right, the assist does have a different intent than this one, nevermind then. |
|
What do I need to do?
|
|
Nothing, disregard my earlier comment its not applicable to this after all. |
else branches" assist
Add ide-assist: remove else branches
Removes the
elsekeyword and else branches.->
->