mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 12:04:43 +00:00 
			
		
		
		
	Merge pull request #20513 from A4-Tacks/let-in-let-chain
Add let in let-chain completion support
This commit is contained in:
		
						commit
						544ef84898
					
				
					 2 changed files with 17 additions and 3 deletions
				
			
		|  | @ -1176,19 +1176,23 @@ fn classify_name_ref<'db>( | ||||||
|         Some(res) |         Some(res) | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let is_in_condition = |it: &ast::Expr| { |     fn is_in_condition(it: &ast::Expr) -> bool { | ||||||
|         (|| { |         (|| { | ||||||
|             let parent = it.syntax().parent()?; |             let parent = it.syntax().parent()?; | ||||||
|             if let Some(expr) = ast::WhileExpr::cast(parent.clone()) { |             if let Some(expr) = ast::WhileExpr::cast(parent.clone()) { | ||||||
|                 Some(expr.condition()? == *it) |                 Some(expr.condition()? == *it) | ||||||
|             } else if let Some(expr) = ast::IfExpr::cast(parent) { |             } else if let Some(expr) = ast::IfExpr::cast(parent.clone()) { | ||||||
|                 Some(expr.condition()? == *it) |                 Some(expr.condition()? == *it) | ||||||
|  |             } else if let Some(expr) = ast::BinExpr::cast(parent) | ||||||
|  |                 && expr.op_token()?.kind() == T![&&] | ||||||
|  |             { | ||||||
|  |                 Some(is_in_condition(&expr.into())) | ||||||
|             } else { |             } else { | ||||||
|                 None |                 None | ||||||
|             } |             } | ||||||
|         })() |         })() | ||||||
|         .unwrap_or(false) |         .unwrap_or(false) | ||||||
|     }; |     } | ||||||
| 
 | 
 | ||||||
|     let make_path_kind_expr = |expr: ast::Expr| { |     let make_path_kind_expr = |expr: ast::Expr| { | ||||||
|         let it = expr.syntax(); |         let it = expr.syntax(); | ||||||
|  |  | ||||||
|  | @ -2622,3 +2622,13 @@ fn foo() { | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | #[test] | ||||||
|  | fn let_in_condition() { | ||||||
|  |     check_edit("let", r#"fn f() { if $0 {} }"#, r#"fn f() { if let $1 = $0 {} }"#); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[test] | ||||||
|  | fn let_in_let_chain() { | ||||||
|  |     check_edit("let", r#"fn f() { if true && $0 {} }"#, r#"fn f() { if true && let $1 = $0 {} }"#); | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Chayim Refael Friedman
						Chayim Refael Friedman