Skip to content

Commit 5ce8f88

Browse files
committed
Add workspace command picker
1 parent 6752c7d commit 5ce8f88

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

helix-lsp/src/client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ impl Client {
298298
dynamic_registration: Some(false),
299299
..Default::default()
300300
}),
301+
execute_command: Some(lsp::DynamicRegistrationClientCapabilities {
302+
dynamic_registration: Some(false),
303+
}),
301304
..Default::default()
302305
}),
303306
text_document: Some(lsp::TextDocumentClientCapabilities {

helix-term/src/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impl MappableCommand {
268268
file_picker, "Open file picker",
269269
file_picker_in_current_directory, "Open file picker at current working directory",
270270
code_action, "Perform code action",
271+
workspace_command_picker, "Open workspace command picker",
271272
buffer_picker, "Open buffer picker",
272273
jumplist_picker, "Open jumplist picker",
273274
symbol_picker, "Open symbol picker",

helix-term/src/commands/lsp.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,42 @@ pub fn code_action(cx: &mut Context) {
603603
},
604604
)
605605
}
606+
607+
impl ui::menu::Item for lsp::Command {
608+
type Data = ();
609+
fn label(&self, _data: &Self::Data) -> Spans {
610+
self.title.as_str().into()
611+
}
612+
}
613+
614+
pub fn workspace_command_picker(cx: &mut Context) {
615+
let (_, doc) = current!(cx.editor);
616+
617+
let language_server = language_server!(cx.editor, doc);
618+
619+
let options = match &language_server.capabilities().execute_command_provider {
620+
Some(options) => options,
621+
None => return,
622+
};
623+
let commands = options
624+
.commands
625+
.iter()
626+
.map(|command| lsp::Command {
627+
title: command.clone(),
628+
command: command.clone(),
629+
arguments: None,
630+
})
631+
.collect::<Vec<_>>();
632+
cx.callback = Some(Box::new(
633+
|compositor: &mut Compositor, _cx: &mut compositor::Context| {
634+
let picker = ui::Picker::new(commands, (), |cx, command, _action| {
635+
execute_lsp_command(cx.editor, command.clone());
636+
});
637+
compositor.push(Box::new(overlayed(picker)))
638+
},
639+
));
640+
}
641+
606642
pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
607643
let doc = doc!(editor);
608644
let language_server = language_server!(editor, doc);

0 commit comments

Comments
 (0)