Skip to content

Commit

Permalink
Auto merge of #15755 - Young-Flash:cursor_selection, r=lnicola
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 15, 2023
2 parents dbe5392 + bc34e8f commit 65532e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ```
// fn main() {
// let x = Some(1);
// if let Some(_tmp) = x {}
// if let Some(${0:_tmp}) = x {}
// }
// ```
pub(crate) fn replace_is_method_with_if_let_method(
Expand Down Expand Up @@ -44,7 +44,7 @@ pub(crate) fn replace_is_method_with_if_let_method(
};

acc.add(AssistId(assist_id, AssistKind::RefactorRewrite), message, target, |edit| {
let replacement = format!("let {}(_tmp) = {}", text, receiver);
let replacement = format!("let {}({}) = {}", text, "${0:_tmp}", receiver);
edit.replace(target, replacement);
})
}
Expand All @@ -71,7 +71,7 @@ fn main() {
r#"
fn main() {
let x = Some(1);
if let Some(_tmp) = x {}
if let Some(${0:_tmp}) = x {}
}
"#,
);
Expand Down Expand Up @@ -103,7 +103,7 @@ fn main() {
r#"
fn main() {
let x = Ok(1);
if let Ok(_tmp) = x {}
if let Ok(${0:_tmp}) = x {}
}
"#,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/tests/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ fn main() {
r#####"
fn main() {
let x = Some(1);
if let Some(_tmp) = x {}
if let Some(${0:_tmp}) = x {}
}
"#####,
)
Expand Down

0 comments on commit 65532e4

Please sign in to comment.