|
| 1 | +use either::Either; |
1 | 2 | use hir::{ImportPathConfig, ModuleDef};
|
2 | 3 | use ide_db::{
|
3 | 4 | assists::{AssistId, AssistKind},
|
@@ -93,27 +94,30 @@ struct BoolNodeData {
|
93 | 94 | fn find_bool_node(ctx: &AssistContext<'_>) -> Option<BoolNodeData> {
|
94 | 95 | let name: ast::Name = ctx.find_node_at_offset()?;
|
95 | 96 |
|
96 |
| - if let Some(let_stmt) = name.syntax().ancestors().find_map(ast::LetStmt::cast) { |
97 |
| - let bind_pat = match let_stmt.pat()? { |
98 |
| - ast::Pat::IdentPat(pat) => pat, |
99 |
| - _ => { |
100 |
| - cov_mark::hit!(not_applicable_in_non_ident_pat); |
101 |
| - return None; |
102 |
| - } |
103 |
| - }; |
104 |
| - let def = ctx.sema.to_def(&bind_pat)?; |
| 97 | + if let Some(ident_pat) = name.syntax().parent().and_then(ast::IdentPat::cast) { |
| 98 | + let def = ctx.sema.to_def(&ident_pat)?; |
105 | 99 | if !def.ty(ctx.db()).is_bool() {
|
106 | 100 | cov_mark::hit!(not_applicable_non_bool_local);
|
107 | 101 | return None;
|
108 | 102 | }
|
109 | 103 |
|
110 |
| - Some(BoolNodeData { |
111 |
| - target_node: let_stmt.syntax().clone(), |
112 |
| - name, |
113 |
| - ty_annotation: let_stmt.ty(), |
114 |
| - initializer: let_stmt.initializer(), |
115 |
| - definition: Definition::Local(def), |
116 |
| - }) |
| 104 | + let local_definition = Definition::Local(def); |
| 105 | + match ident_pat.syntax().parent().and_then(Either::<ast::Param, ast::LetStmt>::cast)? { |
| 106 | + Either::Left(param) => Some(BoolNodeData { |
| 107 | + target_node: param.syntax().clone(), |
| 108 | + name, |
| 109 | + ty_annotation: param.ty(), |
| 110 | + initializer: None, |
| 111 | + definition: local_definition, |
| 112 | + }), |
| 113 | + Either::Right(let_stmt) => Some(BoolNodeData { |
| 114 | + target_node: let_stmt.syntax().clone(), |
| 115 | + name, |
| 116 | + ty_annotation: let_stmt.ty(), |
| 117 | + initializer: let_stmt.initializer(), |
| 118 | + definition: local_definition, |
| 119 | + }), |
| 120 | + } |
117 | 121 | } else if let Some(const_) = name.syntax().parent().and_then(ast::Const::cast) {
|
118 | 122 | let def = ctx.sema.to_def(&const_)?;
|
119 | 123 | if !def.ty(ctx.db()).is_bool() {
|
|
0 commit comments