Skip to content

Commit a406574

Browse files
bors[bot]Veykril
andauthored
Merge #11083
11083: fix: Fix inline local assist not working in let stmt initializer r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 22987c7 + 539b0c2 commit a406574

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

crates/ide_assists/src/handlers/inline_local_variable.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
3636
let file_id = ctx.file_id();
3737
let range = ctx.selection_trimmed();
3838
let InlineData { let_stmt, delete_let, references, target } =
39-
if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
40-
inline_let(&ctx.sema, let_stmt, range, file_id)
41-
} else if let Some(path_expr) = ctx.find_node_at_offset::<ast::PathExpr>() {
39+
if let Some(path_expr) = ctx.find_node_at_offset::<ast::PathExpr>() {
4240
inline_usage(&ctx.sema, path_expr, range, file_id)
41+
} else if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
42+
inline_let(&ctx.sema, let_stmt, range, file_id)
4343
} else {
4444
None
4545
}?;
@@ -912,6 +912,28 @@ fn f() {
912912
let bar = 0;
913913
$0foo + bar$0;
914914
}
915+
"#,
916+
);
917+
}
918+
919+
#[test]
920+
fn test_inline_ref_in_let() {
921+
check_assist(
922+
inline_local_variable,
923+
r#"
924+
fn f() {
925+
let x = {
926+
let y = 0;
927+
y$0
928+
};
929+
}
930+
"#,
931+
r#"
932+
fn f() {
933+
let x = {
934+
0
935+
};
936+
}
915937
"#,
916938
);
917939
}

0 commit comments

Comments
 (0)