Auto merge of #12032 - jonas-schievink:code-action-commands, r=jonas-schievink
feat: display signature help when applying "Add `::<>`" assist Closes https://github.com/rust-lang/rust-analyzer/issues/12031
This commit is contained in:
commit
55824021e1
@ -45,6 +45,7 @@ pub(crate) fn ssr_assists(
|
|||||||
group: Some(GroupLabel("Apply SSR".into())),
|
group: Some(GroupLabel("Apply SSR".into())),
|
||||||
target: comment_range,
|
target: comment_range,
|
||||||
source_change,
|
source_change,
|
||||||
|
trigger_signature_help: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
ssr_assists.push(assist);
|
ssr_assists.push(assist);
|
||||||
@ -140,6 +141,7 @@ mod tests {
|
|||||||
is_snippet: false,
|
is_snippet: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&apply_in_file_assist);
|
.assert_debug_eq(&apply_in_file_assist);
|
||||||
@ -186,6 +188,7 @@ mod tests {
|
|||||||
is_snippet: false,
|
is_snippet: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&apply_in_workspace_assist);
|
.assert_debug_eq(&apply_in_workspace_assist);
|
||||||
@ -225,6 +228,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
target: 10..21,
|
target: 10..21,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&apply_in_file_assist);
|
.assert_debug_eq(&apply_in_file_assist);
|
||||||
@ -244,6 +248,7 @@ mod tests {
|
|||||||
),
|
),
|
||||||
target: 10..21,
|
target: 10..21,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&apply_in_workspace_assist);
|
.assert_debug_eq(&apply_in_workspace_assist);
|
||||||
|
@ -193,9 +193,11 @@ impl Assists {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut trigger_signature_help = false;
|
||||||
let source_change = if self.resolve.should_resolve(&id) {
|
let source_change = if self.resolve.should_resolve(&id) {
|
||||||
let mut builder = AssistBuilder::new(self.file);
|
let mut builder = AssistBuilder::new(self.file);
|
||||||
f(&mut builder);
|
f(&mut builder);
|
||||||
|
trigger_signature_help = builder.trigger_signature_help;
|
||||||
Some(builder.finish())
|
Some(builder.finish())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -203,7 +205,7 @@ impl Assists {
|
|||||||
|
|
||||||
let label = Label::new(label);
|
let label = Label::new(label);
|
||||||
let group = group.cloned();
|
let group = group.cloned();
|
||||||
self.buf.push(Assist { id, label, group, target, source_change });
|
self.buf.push(Assist { id, label, group, target, source_change, trigger_signature_help });
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +221,7 @@ pub(crate) struct AssistBuilder {
|
|||||||
edit: TextEditBuilder,
|
edit: TextEditBuilder,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
source_change: SourceChange,
|
source_change: SourceChange,
|
||||||
|
trigger_signature_help: bool,
|
||||||
|
|
||||||
/// Maps the original, immutable `SyntaxNode` to a `clone_for_update` twin.
|
/// Maps the original, immutable `SyntaxNode` to a `clone_for_update` twin.
|
||||||
mutated_tree: Option<TreeMutator>,
|
mutated_tree: Option<TreeMutator>,
|
||||||
@ -252,6 +255,7 @@ impl AssistBuilder {
|
|||||||
edit: TextEdit::builder(),
|
edit: TextEdit::builder(),
|
||||||
file_id,
|
file_id,
|
||||||
source_change: SourceChange::default(),
|
source_change: SourceChange::default(),
|
||||||
|
trigger_signature_help: false,
|
||||||
mutated_tree: None,
|
mutated_tree: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,6 +336,9 @@ impl AssistBuilder {
|
|||||||
let file_system_edit = FileSystemEdit::MoveFile { src, dst };
|
let file_system_edit = FileSystemEdit::MoveFile { src, dst };
|
||||||
self.source_change.push_file_system_edit(file_system_edit);
|
self.source_change.push_file_system_edit(file_system_edit);
|
||||||
}
|
}
|
||||||
|
pub(crate) fn trigger_signature_help(&mut self) {
|
||||||
|
self.trigger_signature_help = true;
|
||||||
|
}
|
||||||
|
|
||||||
fn finish(mut self) -> SourceChange {
|
fn finish(mut self) -> SourceChange {
|
||||||
self.commit();
|
self.commit();
|
||||||
|
@ -89,15 +89,18 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
|
|||||||
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
|
AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
|
||||||
"Add `::<>`",
|
"Add `::<>`",
|
||||||
ident.text_range(),
|
ident.text_range(),
|
||||||
|builder| match ctx.config.snippet_cap {
|
|builder| {
|
||||||
Some(cap) => {
|
builder.trigger_signature_help();
|
||||||
let snip = format!("::<{}>", get_snippet_fish_head(number_of_arguments));
|
match ctx.config.snippet_cap {
|
||||||
builder.insert_snippet(cap, ident.text_range().end(), snip)
|
Some(cap) => {
|
||||||
}
|
let snip = format!("::<{}>", get_snippet_fish_head(number_of_arguments));
|
||||||
None => {
|
builder.insert_snippet(cap, ident.text_range().end(), snip)
|
||||||
let fish_head = std::iter::repeat("_").take(number_of_arguments).format(", ");
|
}
|
||||||
let snip = format!("::<{}>", fish_head);
|
None => {
|
||||||
builder.insert(ident.text_range().end(), snip);
|
let fish_head = std::iter::repeat("_").take(number_of_arguments).format(", ");
|
||||||
|
let snip = format!("::<{}>", fish_head);
|
||||||
|
builder.insert(ident.text_range().end(), snip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -341,6 +341,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
group: None,
|
group: None,
|
||||||
target: 59..60,
|
target: 59..60,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_variable_assist);
|
.assert_debug_eq(&extract_into_variable_assist);
|
||||||
@ -356,6 +357,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
group: None,
|
group: None,
|
||||||
target: 59..60,
|
target: 59..60,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_function_assist);
|
.assert_debug_eq(&extract_into_function_assist);
|
||||||
@ -385,6 +387,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
group: None,
|
group: None,
|
||||||
target: 59..60,
|
target: 59..60,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_variable_assist);
|
.assert_debug_eq(&extract_into_variable_assist);
|
||||||
@ -400,6 +403,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
group: None,
|
group: None,
|
||||||
target: 59..60,
|
target: 59..60,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_function_assist);
|
.assert_debug_eq(&extract_into_function_assist);
|
||||||
@ -450,6 +454,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
is_snippet: true,
|
is_snippet: true,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_variable_assist);
|
.assert_debug_eq(&extract_into_variable_assist);
|
||||||
@ -465,6 +470,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
group: None,
|
group: None,
|
||||||
target: 59..60,
|
target: 59..60,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_function_assist);
|
.assert_debug_eq(&extract_into_function_assist);
|
||||||
@ -507,6 +513,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
is_snippet: true,
|
is_snippet: true,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_variable_assist);
|
.assert_debug_eq(&extract_into_variable_assist);
|
||||||
@ -543,6 +550,7 @@ pub fn test_some_range(a: int) -> bool {
|
|||||||
is_snippet: true,
|
is_snippet: true,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
"#]]
|
"#]]
|
||||||
.assert_debug_eq(&extract_into_function_assist);
|
.assert_debug_eq(&extract_into_function_assist);
|
||||||
|
@ -29,6 +29,7 @@ pub struct Assist {
|
|||||||
/// cumbersome, especially if you want to embed an assist into another data
|
/// cumbersome, especially if you want to embed an assist into another data
|
||||||
/// structure, such as a diagnostic.
|
/// structure, such as a diagnostic.
|
||||||
pub source_change: Option<SourceChange>,
|
pub source_change: Option<SourceChange>,
|
||||||
|
pub trigger_signature_help: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
@ -117,6 +117,7 @@ mod baz {}
|
|||||||
is_snippet: false,
|
is_snippet: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
},
|
},
|
||||||
Assist {
|
Assist {
|
||||||
id: AssistId(
|
id: AssistId(
|
||||||
@ -143,6 +144,7 @@ mod baz {}
|
|||||||
is_snippet: false,
|
is_snippet: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
trigger_signature_help: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -238,5 +238,6 @@ fn unresolved_fix(id: &'static str, label: &str, target: TextRange) -> Assist {
|
|||||||
group: None,
|
group: None,
|
||||||
target,
|
target,
|
||||||
source_change: None,
|
source_change: None,
|
||||||
|
trigger_signature_help: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,6 +318,7 @@
|
|||||||
"quickfix",
|
"quickfix",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
command: None,
|
||||||
edit: Some(
|
edit: Some(
|
||||||
SnippetWorkspaceEdit {
|
SnippetWorkspaceEdit {
|
||||||
changes: Some(
|
changes: Some(
|
||||||
|
@ -165,6 +165,7 @@
|
|||||||
"quickfix",
|
"quickfix",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
command: None,
|
||||||
edit: Some(
|
edit: Some(
|
||||||
SnippetWorkspaceEdit {
|
SnippetWorkspaceEdit {
|
||||||
changes: Some(
|
changes: Some(
|
||||||
|
@ -165,6 +165,7 @@
|
|||||||
"quickfix",
|
"quickfix",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
command: None,
|
||||||
edit: Some(
|
edit: Some(
|
||||||
SnippetWorkspaceEdit {
|
SnippetWorkspaceEdit {
|
||||||
changes: Some(
|
changes: Some(
|
||||||
|
@ -165,6 +165,7 @@
|
|||||||
"quickfix",
|
"quickfix",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
command: None,
|
||||||
edit: Some(
|
edit: Some(
|
||||||
SnippetWorkspaceEdit {
|
SnippetWorkspaceEdit {
|
||||||
changes: Some(
|
changes: Some(
|
||||||
|
@ -328,6 +328,7 @@
|
|||||||
"quickfix",
|
"quickfix",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
command: None,
|
||||||
edit: Some(
|
edit: Some(
|
||||||
SnippetWorkspaceEdit {
|
SnippetWorkspaceEdit {
|
||||||
changes: Some(
|
changes: Some(
|
||||||
|
@ -204,6 +204,7 @@ fn map_rust_child_diagnostic(
|
|||||||
}),
|
}),
|
||||||
is_preferred: Some(true),
|
is_preferred: Some(true),
|
||||||
data: None,
|
data: None,
|
||||||
|
command: None,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
@ -1160,8 +1160,9 @@ pub(crate) fn handle_code_action_resolve(
|
|||||||
))
|
))
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
let edit = to_proto::code_action(&snap, assist.clone(), None)?.edit;
|
let ca = to_proto::code_action(&snap, assist.clone(), None)?;
|
||||||
code_action.edit = edit;
|
code_action.edit = ca.edit;
|
||||||
|
code_action.command = ca.command;
|
||||||
Ok(code_action)
|
Ok(code_action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,9 +311,8 @@ pub struct CodeAction {
|
|||||||
pub group: Option<String>,
|
pub group: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub kind: Option<CodeActionKind>,
|
pub kind: Option<CodeActionKind>,
|
||||||
// We don't handle commands on the client-side
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
pub command: Option<lsp_types::Command>,
|
||||||
// pub command: Option<lsp_types::Command>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub edit: Option<SnippetWorkspaceEdit>,
|
pub edit: Option<SnippetWorkspaceEdit>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
@ -1018,7 +1018,13 @@ pub(crate) fn code_action(
|
|||||||
edit: None,
|
edit: None,
|
||||||
is_preferred: None,
|
is_preferred: None,
|
||||||
data: None,
|
data: None,
|
||||||
|
command: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if assist.trigger_signature_help && snap.config.client_commands().trigger_parameter_hints {
|
||||||
|
res.command = Some(command::trigger_parameter_hints());
|
||||||
|
}
|
||||||
|
|
||||||
match (assist.source_change, resolve_data) {
|
match (assist.source_change, resolve_data) {
|
||||||
(Some(it), _) => res.edit = Some(snippet_workspace_edit(snap, it)?),
|
(Some(it), _) => res.edit = Some(snippet_workspace_edit(snap, it)?),
|
||||||
(None, Some((index, code_action_params))) => {
|
(None, Some((index, code_action_params))) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!---
|
<!---
|
||||||
lsp_ext.rs hash: 326ad62235135223
|
lsp_ext.rs hash: 7a34bc3f38e2a7d8
|
||||||
|
|
||||||
If you need to change the above hash to make the test pass, please check if you
|
If you need to change the above hash to make the test pass, please check if you
|
||||||
need to adjust this doc as well and ping this issue:
|
need to adjust this doc as well and ping this issue:
|
||||||
|
@ -735,6 +735,9 @@ export function resolveCodeAction(ctx: Ctx): Cmd {
|
|||||||
const fileSystemEdit = await client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit);
|
const fileSystemEdit = await client.protocol2CodeConverter.asWorkspaceEdit(lcFileSystemEdit);
|
||||||
await vscode.workspace.applyEdit(fileSystemEdit);
|
await vscode.workspace.applyEdit(fileSystemEdit);
|
||||||
await applySnippetWorkspaceEdit(edit);
|
await applySnippetWorkspaceEdit(edit);
|
||||||
|
if (item.command != null) {
|
||||||
|
await vscode.commands.executeCommand(item.command.command, item.command.arguments);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user