mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Trigger VSCode to rename after extract variable assist is applied
When the user applies the "Extract Variable" assist, the cursor is positioned at the newly inserted variable. This commit adds a command to the assist that triggers the rename action in VSCode. This way, the user can quickly rename the variable after applying the assist. Fixes part of: #17579
This commit is contained in:
parent
5577e4e3b1
commit
8efe8a8528
17 changed files with 80 additions and 33 deletions
|
@ -185,11 +185,11 @@ impl Assists {
|
|||
return None;
|
||||
}
|
||||
|
||||
let mut trigger_signature_help = false;
|
||||
let mut command = None;
|
||||
let source_change = if self.resolve.should_resolve(&id) {
|
||||
let mut builder = SourceChangeBuilder::new(self.file);
|
||||
f(&mut builder);
|
||||
trigger_signature_help = builder.trigger_signature_help;
|
||||
command = builder.command.take();
|
||||
Some(builder.finish())
|
||||
} else {
|
||||
None
|
||||
|
@ -197,7 +197,7 @@ impl Assists {
|
|||
|
||||
let label = Label::new(label);
|
||||
let group = group.cloned();
|
||||
self.buf.push(Assist { id, label, group, target, source_change, trigger_signature_help });
|
||||
self.buf.push(Assist { id, label, group, target, source_change, command });
|
||||
Some(())
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
|||
}
|
||||
}
|
||||
}
|
||||
edit.rename();
|
||||
}
|
||||
Anchor::Replace(stmt) => {
|
||||
cov_mark::hit!(test_extract_var_expr_stmt);
|
||||
|
@ -149,6 +150,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
|||
}
|
||||
}
|
||||
}
|
||||
edit.rename();
|
||||
}
|
||||
Anchor::WrapInBlock(to_wrap) => {
|
||||
let indent_to = to_wrap.indent_level();
|
||||
|
@ -192,6 +194,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
|||
}
|
||||
}
|
||||
}
|
||||
edit.rename();
|
||||
|
||||
// fixup indentation of block
|
||||
block.indent(indent_to);
|
||||
|
|
|
@ -454,7 +454,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||
group: None,
|
||||
target: 59..60,
|
||||
source_change: None,
|
||||
trigger_signature_help: false,
|
||||
command: None,
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_variable_assist);
|
||||
|
@ -470,7 +470,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||
group: None,
|
||||
target: 59..60,
|
||||
source_change: None,
|
||||
trigger_signature_help: false,
|
||||
command: None,
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_function_assist);
|
||||
|
@ -500,7 +500,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||
group: None,
|
||||
target: 59..60,
|
||||
source_change: None,
|
||||
trigger_signature_help: false,
|
||||
command: None,
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_variable_assist);
|
||||
|
@ -516,7 +516,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||
group: None,
|
||||
target: 59..60,
|
||||
source_change: None,
|
||||
trigger_signature_help: false,
|
||||
command: None,
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_function_assist);
|
||||
|
@ -587,7 +587,9 @@ pub fn test_some_range(a: int) -> bool {
|
|||
is_snippet: true,
|
||||
},
|
||||
),
|
||||
trigger_signature_help: false,
|
||||
command: Some(
|
||||
Rename,
|
||||
),
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_variable_assist);
|
||||
|
@ -603,7 +605,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||
group: None,
|
||||
target: 59..60,
|
||||
source_change: None,
|
||||
trigger_signature_help: false,
|
||||
command: None,
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_function_assist);
|
||||
|
@ -666,7 +668,9 @@ pub fn test_some_range(a: int) -> bool {
|
|||
is_snippet: true,
|
||||
},
|
||||
),
|
||||
trigger_signature_help: false,
|
||||
command: Some(
|
||||
Rename,
|
||||
),
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_variable_assist);
|
||||
|
@ -715,7 +719,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||
is_snippet: true,
|
||||
},
|
||||
),
|
||||
trigger_signature_help: false,
|
||||
command: None,
|
||||
}
|
||||
"#]]
|
||||
.assert_debug_eq(&extract_into_function_assist);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue