on master help sign in
Improve code action picker by displaying it inline
commitf7f55143a1c8f8f643c4ca59d8c4beb9612ef0bb authorBlaž Hrastnik <blaz@mxxn.io> dateMon 31 Jan 2022, 12:36 (5 years ago) parent4c996f4
2 files changed+19−3
helix-term/src/commands.rs+9−3 helix-term/src/ui/picker.rs+10
helix-term/src/commands.rs+9−3
@@ -3482,12 +3482,17 @@ pub fn code_action(cx: &mut Context) {
34823482
34833483 cx.callback(
34843484 future,
3485− move |_editor: &mut Editor,
3485+ move |editor: &mut Editor,
34863486 compositor: &mut Compositor,
34873487 response: Option<lsp::CodeActionResponse>| {
34883488 if let Some(actions) = response {
3489+ if actions.is_empty() {
3490+ editor.set_status("No code actions available".to_owned());
3491+ return;
3492+ }
3493+
34893494 let picker = Picker::new(
3490− true,
3495+ false,
34913496 actions,
34923497 |action| match action {
34933498 lsp::CodeActionOrCommand::CodeAction(action) => {
@@ -3515,7 +3520,8 @@ pub fn code_action(cx: &mut Context) {
35153520 }
35163521 },
35173522 );
3518− compositor.push(Box::new(picker))
3523+ let popup = Popup::new("code-action", picker);
3524+ compositor.push(Box::new(popup))
35193525 }
35203526 },
35213527 )
helix-term/src/ui/picker.rs+10
@@ -393,6 +393,16 @@ fn inner_rect(area: Rect) -> Rect {
393393}
394394
395395impl<T: 'static> Component for Picker<T> {
396+ fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
397+ let max_width = 50.min(viewport.0);
398+ let max_height = 10.min(viewport.1.saturating_sub(2)); // add some spacing in the viewport
399+
400+ let height = (self.options.len() as u16 + 4) // add some spacing for input + padding
401+ .min(max_height);
402+ let width = max_width;
403+ Some((width, height))
404+ }
405+
396406 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
397407 let key_event = match event {
398408 Event::Key(event) => event,