Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 2cbdeb45..9fbb61be 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -6817,3 +6817,44 @@ fn jump_to_word(cx: &mut Context, behaviour: Movement) {
}
jump_to_label(cx, words, behaviour)
}
+
+pub fn code_action(cx: &mut Context) {
+ impl ui::menu::Item for helix_view::Action {
+ type Data = ();
+ fn format(&self, _data: &Self::Data) -> ui::menu::Row {
+ self.title().into()
+ }
+ }
+
+ let Some(future) = cx.editor.actions() else {
+ cx.editor.set_error("No code actions available");
+ return;
+ };
+
+ cx.jobs.callback(async move {
+ let actions = future.await;
+
+ let call = move |editor: &mut Editor, compositor: &mut Compositor| {
+ if actions.is_empty() {
+ editor.set_error("No code actions available");
+ return;
+ }
+ let mut picker = ui::Menu::new(actions, (), move |editor, action, event| {
+ if event != PromptEvent::Validate {
+ return;
+ }
+
+ // always present here
+ let action = action.unwrap();
+ action.execute(editor);
+ });
+ picker.move_down(); // pre-select the first item
+
+ let popup = Popup::new("code-action", picker).with_scrollbar(false);
+
+ compositor.replace_or_push("code-action", popup);
+ };
+
+ Ok(Callback::EditorCompositor(Box::new(call)))
+ });
+}