Add workspace command picker

imgbot
MDeiml 2 years ago
parent 76756f0e5d
commit 90d40b70e8

@ -295,6 +295,9 @@ impl Client {
}), }),
workspace_folders: Some(true), workspace_folders: Some(true),
apply_edit: Some(true), apply_edit: Some(true),
execute_command: Some(lsp::DynamicRegistrationClientCapabilities {
dynamic_registration: Some(false),
}),
..Default::default() ..Default::default()
}), }),
text_document: Some(lsp::TextDocumentClientCapabilities { text_document: Some(lsp::TextDocumentClientCapabilities {

@ -263,6 +263,7 @@ impl MappableCommand {
file_picker, "Open file picker", file_picker, "Open file picker",
file_picker_in_current_directory, "Open file picker at current working directory", file_picker_in_current_directory, "Open file picker at current working directory",
code_action, "Perform code action", code_action, "Perform code action",
workspace_command_picker, "Open workspace command picker",
buffer_picker, "Open buffer picker", buffer_picker, "Open buffer picker",
symbol_picker, "Open symbol picker", symbol_picker, "Open symbol picker",
select_references_to_symbol_under_cursor, "Select symbol references", select_references_to_symbol_under_cursor, "Select symbol references",

@ -497,6 +497,42 @@ pub fn code_action(cx: &mut Context) {
}, },
) )
} }
impl ui::menu::Item for lsp::Command {
type Data = ();
fn label(&self, _data: &Self::Data) -> Spans {
self.title.as_str().into()
}
}
pub fn workspace_command_picker(cx: &mut Context) {
let (_, doc) = current!(cx.editor);
let language_server = language_server!(cx.editor, doc);
let execute_command_provider = match &language_server.capabilities().execute_command_provider {
Some(p) => p,
None => return,
};
let commands = execute_command_provider
.commands
.iter()
.map(|command| lsp::Command {
title: command.clone(),
command: command.clone(),
arguments: None,
})
.collect::<Vec<_>>();
cx.callback = Some(Box::new(
move |compositor: &mut Compositor, _cx: &mut compositor::Context| {
let picker = ui::Picker::new(commands, (), move |cx, command, _action| {
execute_lsp_command(cx.editor, command.clone());
});
compositor.push(Box::new(overlayed(picker)))
},
));
}
pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) { pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
let doc = doc!(editor); let doc = doc!(editor);
let language_server = language_server!(editor, doc); let language_server = language_server!(editor, doc);

Loading…
Cancel
Save