on master help sign in
Improve code action picker by displaying it inline
f7f5514Blaž Hrastnik
helix-term/src/commands.rs+9−3
@@ -3482,12 +3482,17 @@ pub fn code_action(cx: &mut Context) {
3482
3482
3483 cx.callback(
3483 cx.callback(
3484 future,
3484 future,
3485− move |_editor: &mut Editor,
3485+ move |editor: &mut Editor,
3486 compositor: &mut Compositor,
3486 compositor: &mut Compositor,
3487 response: Option<lsp::CodeActionResponse>| {
3487 response: Option<lsp::CodeActionResponse>| {
3488 if let Some(actions) = response {
3488 if let Some(actions) = response {
3489+ if actions.is_empty() {
3490+ editor.set_status("No code actions available".to_owned());
3491+ return;
3492+ }
3493+
3489 let picker = Picker::new(
3494 let picker = Picker::new(
3490− true,
3495+ false,
3491 actions,
3496 actions,
3492 |action| match action {
3497 |action| match action {
3493 lsp::CodeActionOrCommand::CodeAction(action) => {
3498 lsp::CodeActionOrCommand::CodeAction(action) => {
@@ -3515,7 +3520,8 @@ pub fn code_action(cx: &mut Context) {
3515 }
3520 }
3516 },
3521 },
3517 );
3522 );
3523+ let popup = Popup::new("code-action", picker);
3518− compositor.push(Box::new(picker))
3524+ compositor.push(Box::new(popup))
3519 }
3525 }
3520 },
3526 },
3521 )
3527 )
helix-term/src/ui/picker.rs+10
@@ -393,6 +393,16 @@ fn inner_rect(area: Rect) -> Rect {
393}
393}
394
394
395impl<T: 'static> Component for Picker<T> {
395impl<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+
396 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
406 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
397 let key_event = match event {
407 let key_event = match event {
398 Event::Key(event) => event,
408 Event::Key(event) => event,