Skip to content

Commit

Permalink
Add workspace command picker
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeiml committed Jul 21, 2022
1 parent 76756f0 commit bb62de7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ impl Client {
}),
workspace_folders: Some(true),
apply_edit: Some(true),
execute_command: Some(lsp::DynamicRegistrationClientCapabilities {
dynamic_registration: Some(false),
}),
..Default::default()
}),
text_document: Some(lsp::TextDocumentClientCapabilities {
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl MappableCommand {
file_picker, "Open file picker",
file_picker_in_current_directory, "Open file picker at current working directory",
code_action, "Perform code action",
workspace_command_picker, "Open workspace command picker",
buffer_picker, "Open buffer picker",
symbol_picker, "Open symbol picker",
select_references_to_symbol_under_cursor, "Select symbol references",
Expand Down
38 changes: 38 additions & 0 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,44 @@ 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<_>>();
log::debug!("outside {:?}", commands);
cx.callback = Some(Box::new(
move |compositor: &mut Compositor, _cx: &mut compositor::Context| {
log::debug!("inside {:?}", commands);
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) {
let doc = doc!(editor);
let language_server = language_server!(editor, doc);
Expand Down

0 comments on commit bb62de7

Please sign in to comment.