Unnamed repository; edit this file 'description' to name the repository.
fix: Fix inline local assist not working in let stmt initializer
Lukas Wirth 2021-12-21
parent 8e08413 · commit 539b0c2
-rw-r--r--crates/ide_assists/src/handlers/inline_local_variable.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/crates/ide_assists/src/handlers/inline_local_variable.rs b/crates/ide_assists/src/handlers/inline_local_variable.rs
index 8e528c8e39..1fce654df2 100644
--- a/crates/ide_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ide_assists/src/handlers/inline_local_variable.rs
@@ -36,10 +36,10 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
let file_id = ctx.file_id();
let range = ctx.selection_trimmed();
let InlineData { let_stmt, delete_let, references, target } =
- if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
- inline_let(&ctx.sema, let_stmt, range, file_id)
- } else if let Some(path_expr) = ctx.find_node_at_offset::<ast::PathExpr>() {
+ if let Some(path_expr) = ctx.find_node_at_offset::<ast::PathExpr>() {
inline_usage(&ctx.sema, path_expr, range, file_id)
+ } else if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
+ inline_let(&ctx.sema, let_stmt, range, file_id)
} else {
None
}?;
@@ -915,4 +915,26 @@ fn f() {
"#,
);
}
+
+ #[test]
+ fn test_inline_ref_in_let() {
+ check_assist(
+ inline_local_variable,
+ r#"
+fn f() {
+ let x = {
+ let y = 0;
+ y$0
+ };
+}
+"#,
+ r#"
+fn f() {
+ let x = {
+ 0
+ };
+}
+"#,
+ );
+ }
}