Skip to content
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

bool_to_enum assist should work on parameters #17400

Closed
Veykril opened this issue Jun 12, 2024 · 1 comment · Fixed by #17467
Closed

bool_to_enum assist should work on parameters #17400

Veykril opened this issue Jun 12, 2024 · 1 comment · Fixed by #17467
Assignees
Labels
A-assists C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@Veykril
Copy link
Member

Veykril commented Jun 12, 2024

https://github.com/rust-lang/rust-analyzer/blob/4af21ffb026c7ec3a97a484ca27b36f703eb5fb1/crates/ide-assists/src/handlers/bool_to_enum.rs currently only works on "local variables, fields, constants, and statics", parameters should be included in the local variables part but that is not the case as we look for LetStmt here

if let Some(let_stmt) = name.syntax().ancestors().find_map(ast::LetStmt::cast) {
let bind_pat = match let_stmt.pat()? {
ast::Pat::IdentPat(pat) => pat,
_ => {
cov_mark::hit!(not_applicable_in_non_ident_pat);
return None;
}
};
let def = ctx.sema.to_def(&bind_pat)?;
if !def.ty(ctx.db()).is_bool() {
cov_mark::hit!(not_applicable_non_bool_local);
return None;
}
Some(BoolNodeData {
target_node: let_stmt.syntax().clone(),
name,
ty_annotation: let_stmt.ty(),
initializer: let_stmt.initializer(),
definition: Definition::Local(def),
})
} else if let Some(const_) = name.syntax().parent().and_then(ast::Const::cast) {
opposed to looking for patterns.

So instead of looking for the statement this should look for the IdentPat directly, then check if that is within a let statement or parameter and act accordingly.

@Veykril Veykril added E-has-instructions Issue has some instructions and pointers to code to get started A-assists C-feature Category: feature request labels Jun 12, 2024
@winstxnhdw
Copy link
Contributor

winstxnhdw commented Jun 14, 2024

Hey @Veykril, I'd like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants