From f7f55143a1c8f8f643c4ca59d8c4beb9612ef0bb Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 31 Jan 2022 12:36:36 +0900 Subject: Improve code action picker by displaying it inline --- helix-term/src/commands.rs | 12 +++++++++--- helix-term/src/ui/picker.rs | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9d140662..96acb424 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3482,12 +3482,17 @@ pub fn code_action(cx: &mut Context) { cx.callback( future, - move |_editor: &mut Editor, + move |editor: &mut Editor, compositor: &mut Compositor, response: Option| { if let Some(actions) = response { + if actions.is_empty() { + editor.set_status("No code actions available".to_owned()); + return; + } + let picker = Picker::new( - true, + false, actions, |action| match action { lsp::CodeActionOrCommand::CodeAction(action) => { @@ -3515,7 +3520,8 @@ pub fn code_action(cx: &mut Context) { } }, ); - compositor.push(Box::new(picker)) + let popup = Popup::new("code-action", picker); + compositor.push(Box::new(popup)) } }, ) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 945e14bb..4068a2d4 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -393,6 +393,16 @@ fn inner_rect(area: Rect) -> Rect { } impl Component for Picker { + fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { + let max_width = 50.min(viewport.0); + let max_height = 10.min(viewport.1.saturating_sub(2)); // add some spacing in the viewport + + let height = (self.options.len() as u16 + 4) // add some spacing for input + padding + .min(max_height); + let width = max_width; + Some((width, height)) + } + fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { let key_event = match event { Event::Key(event) => event, -- cgit v1.2.3-70-g09d2