Skip to content

Commit 4980ad6

Browse files
MDeimlthe-mikedavis
authored andcommitted
Add workspace command picker
1 parent e80beaa commit 4980ad6

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
@@ -266,6 +266,7 @@ impl MappableCommand {
266266
file_picker, "Open file picker",
267267
file_picker_in_current_directory, "Open file picker at current working directory",
268268
code_action, "Perform code action",
269+
workspace_command_picker, "Open workspace command picker",
269270
buffer_picker, "Open buffer picker",
270271
jumplist_picker, "Open jumplist picker",
271272
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
@@ -496,6 +496,42 @@ pub fn code_action(cx: &mut Context) {
496496
},
497497
)
498498
}
499+
500+
impl ui::menu::Item for lsp::Command {
501+
type Data = ();
502+
fn label(&self, _data: &Self::Data) -> Spans {
503+
self.title.as_str().into()
504+
}
505+
}
506+
507+
pub fn workspace_command_picker(cx: &mut Context) {
508+
let (_, doc) = current!(cx.editor);
509+
510+
let language_server = language_server!(cx.editor, doc);
511+
512+
let execute_command_provider = match &language_server.capabilities().execute_command_provider {
513+
Some(p) => p,
514+
None => return,
515+
};
516+
let commands = execute_command_provider
517+
.commands
518+
.iter()
519+
.map(|command| lsp::Command {
520+
title: command.clone(),
521+
command: command.clone(),
522+
arguments: None,
523+
})
524+
.collect::<Vec<_>>();
525+
cx.callback = Some(Box::new(
526+
move |compositor: &mut Compositor, _cx: &mut compositor::Context| {
527+
let picker = ui::Picker::new(commands, (), move |cx, command, _action| {
528+
execute_lsp_command(cx.editor, command.clone());
529+
});
530+
compositor.push(Box::new(overlayed(picker)))
531+
},
532+
));
533+
}
534+
499535
pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
500536
let doc = doc!(editor);
501537
let language_server = language_server!(editor, doc);

0 commit comments

Comments
 (0)