Skip to content

Commit 65532e4

Browse files
committed
Auto merge of #15755 - Young-Flash:cursor_selection, r=lnicola
fix: make cursor select at _tmp Here make cursor select at `_tmp` atuomatically after the assist apply. Refer to [vscode snippet placeholder](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_placeholders). ![cursor_selection](https://github.com/rust-lang/rust-analyzer/assets/71162630/a7866efe-2d54-488b-903e-9df039f34a7e) following rust-lang/rust-analyzer#15752
2 parents dbe5392 + bc34e8f commit 65532e4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
1616
// ```
1717
// fn main() {
1818
// let x = Some(1);
19-
// if let Some(_tmp) = x {}
19+
// if let Some(${0:_tmp}) = x {}
2020
// }
2121
// ```
2222
pub(crate) fn replace_is_method_with_if_let_method(
@@ -44,7 +44,7 @@ pub(crate) fn replace_is_method_with_if_let_method(
4444
};
4545

4646
acc.add(AssistId(assist_id, AssistKind::RefactorRewrite), message, target, |edit| {
47-
let replacement = format!("let {}(_tmp) = {}", text, receiver);
47+
let replacement = format!("let {}({}) = {}", text, "${0:_tmp}", receiver);
4848
edit.replace(target, replacement);
4949
})
5050
}
@@ -71,7 +71,7 @@ fn main() {
7171
r#"
7272
fn main() {
7373
let x = Some(1);
74-
if let Some(_tmp) = x {}
74+
if let Some(${0:_tmp}) = x {}
7575
}
7676
"#,
7777
);
@@ -103,7 +103,7 @@ fn main() {
103103
r#"
104104
fn main() {
105105
let x = Ok(1);
106-
if let Ok(_tmp) = x {}
106+
if let Ok(${0:_tmp}) = x {}
107107
}
108108
"#,
109109
);

crates/ide-assists/src/tests/generated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,7 @@ fn main() {
25712571
r#####"
25722572
fn main() {
25732573
let x = Some(1);
2574-
if let Some(_tmp) = x {}
2574+
if let Some(${0:_tmp}) = x {}
25752575
}
25762576
"#####,
25772577
)

0 commit comments

Comments
 (0)