aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api_light
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api_light')
-rw-r--r--crates/ra_ide_api_light/src/assists/introduce_variable.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/crates/ra_ide_api_light/src/assists/introduce_variable.rs b/crates/ra_ide_api_light/src/assists/introduce_variable.rs
index 523ec7034..3e4434c23 100644
--- a/crates/ra_ide_api_light/src/assists/introduce_variable.rs
+++ b/crates/ra_ide_api_light/src/assists/introduce_variable.rs
@@ -20,12 +20,16 @@ pub fn introduce_variable<'a>(ctx: AssistCtx) -> Option<Assist> {
20 20
21 buf.push_str("let var_name = "); 21 buf.push_str("let var_name = ");
22 expr.syntax().text().push_to(&mut buf); 22 expr.syntax().text().push_to(&mut buf);
23 let is_full_stmt = if let Some(expr_stmt) = ast::ExprStmt::cast(anchor_stmt) { 23 let full_stmt = ast::ExprStmt::cast(anchor_stmt);
24 let is_full_stmt = if let Some(expr_stmt) = full_stmt {
24 Some(expr.syntax()) == expr_stmt.expr().map(|e| e.syntax()) 25 Some(expr.syntax()) == expr_stmt.expr().map(|e| e.syntax())
25 } else { 26 } else {
26 false 27 false
27 }; 28 };
28 if is_full_stmt { 29 if is_full_stmt {
30 if !full_stmt.unwrap().has_semi() {
31 buf.push_str(";");
32 }
29 edit.replace(expr.syntax().range(), buf); 33 edit.replace(expr.syntax().range(), buf);
30 } else { 34 } else {
31 buf.push_str(";"); 35 buf.push_str(";");
@@ -141,4 +145,20 @@ fn foo() {
141 ); 145 );
142 } 146 }
143 147
148 #[test]
149 fn test_introduce_var_block_expr_second_to_last() {
150 check_assist_range(
151 introduce_variable,
152 "
153fn foo() {
154 <|>{ let x = 0; x }<|>
155 something_else();
156}",
157 "
158fn foo() {
159 let <|>var_name = { let x = 0; x };
160 something_else();
161}",
162 );
163 }
144} 164}