Skip to content

Commit bb62de7

Browse files
committed
Add workspace command picker
1 parent 76756f0 commit bb62de7

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

helix-lsp/src/client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ impl Client {
295295
}),
296296
workspace_folders: Some(true),
297297
apply_edit: Some(true),
298+
execute_command: Some(lsp::DynamicRegistrationClientCapabilities {
299+
dynamic_registration: Some(false),
300+
}),
298301
..Default::default()
299302
}),
300303
text_document: Some(lsp::TextDocumentClientCapabilities {

helix-term/src/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl MappableCommand {
263263
file_picker, "Open file picker",
264264
file_picker_in_current_directory, "Open file picker at current working directory",
265265
code_action, "Perform code action",
266+
workspace_command_picker, "Open workspace command picker",
266267
buffer_picker, "Open buffer picker",
267268
symbol_picker, "Open symbol picker",
268269
select_references_to_symbol_under_cursor, "Select symbol references",

helix-term/src/commands/lsp.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,44 @@ pub fn code_action(cx: &mut Context) {
497497
},
498498
)
499499
}
500+
501+
impl ui::menu::Item for lsp::Command {
502+
type Data = ();
503+
fn label(&self, _data: &Self::Data) -> Spans {
504+
self.title.as_str().into()
505+
}
506+
}
507+
508+
pub fn workspace_command_picker(cx: &mut Context) {
509+
let (_, doc) = current!(cx.editor);
510+
511+
let language_server = language_server!(cx.editor, doc);
512+
513+
let execute_command_provider = match &language_server.capabilities().execute_command_provider {
514+
Some(p) => p,
515+
None => return,
516+
};
517+
let commands = execute_command_provider
518+
.commands
519+
.iter()
520+
.map(|command| lsp::Command {
521+
title: command.clone(),
522+
command: command.clone(),
523+
arguments: None,
524+
})
525+
.collect::<Vec<_>>();
526+
log::debug!("outside {:?}", commands);
527+
cx.callback = Some(Box::new(
528+
move |compositor: &mut Compositor, _cx: &mut compositor::Context| {
529+
log::debug!("inside {:?}", commands);
530+
let picker = ui::Picker::new(commands, (), move |cx, command, _action| {
531+
execute_lsp_command(cx.editor, command.clone());
532+
});
533+
compositor.push(Box::new(overlayed(picker)))
534+
},
535+
));
536+
}
537+
500538
pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
501539
let doc = doc!(editor);
502540
let language_server = language_server!(editor, doc);

0 commit comments

Comments
 (0)