@@ -3494,47 +3494,48 @@ pub fn code_action(cx: &mut Context) {
34943494 move |editor: &mut Editor,
34953495 compositor: &mut Compositor,
34963496 response: Option<lsp::CodeActionResponse>| {
3497− if let Some(actions) = response {
3498− if actions.is_empty() {
3499− editor.set_status("No code actions available".to_owned());
3497+ let actions = match response {
3498+ Some(a) => a,
3499+ None => return,
3500+ };
3501+ if actions.is_empty() {
3502+ editor.set_status("No code actions available".to_owned());
3503+ return;
3504+ }
3505+
3506+ let picker = ui::Menu::new(actions, move |editor, code_action, event| {
3507+ if event != PromptEvent::Validate {
35003508 return;
35013509 }
35023510
3503− let picker = ui::Menu::new(actions, move |editor, code_action, event| {
3504− if event != PromptEvent::Validate {
3505− return;
3506− }
3507−
3508− // always present here
3509− let code_action = code_action.unwrap();
3511+ // always present here
3512+ let code_action = code_action.unwrap();
35103513
3511− match code_action {
3512− lsp::CodeActionOrCommand::Command(command) => {
3513− log::debug!("code action command: {:?}", command);
3514− execute_lsp_command(editor, command.clone());
3514+ match code_action {
3515+ lsp::CodeActionOrCommand::Command(command) => {
3516+ log::debug!("code action command: {:?}", command);
3517+ execute_lsp_command(editor, command.clone());
3518+ }
3519+ lsp::CodeActionOrCommand::CodeAction(code_action) => {
3520+ log::debug!("code action: {:?}", code_action);
3521+ if let Some(ref workspace_edit) = code_action.edit {
3522+ log::debug!("edit: {:?}", workspace_edit);
3523+ apply_workspace_edit(editor, offset_encoding, workspace_edit);
35153524 }
3516− lsp::CodeActionOrCommand::CodeAction(code_action) => {
3517− log::debug!("code action: {:?}", code_action);
3518− if let Some(ref workspace_edit) = code_action.edit {
3519− log::debug!("edit: {:?}", workspace_edit);
3520− apply_workspace_edit(editor, offset_encoding, workspace_edit);
3521− }
35223525
3523− // if code action provides both edit and command first the edit
3524− // should be applied and then the command
3525− if let Some(command) = &code_action.command {
3526− execute_lsp_command(editor, command.clone());
3527− }
3526+ // if code action provides both edit and command first the edit
3527+ // should be applied and then the command
3528+ if let Some(command) = &code_action.command {
3529+ execute_lsp_command(editor, command.clone());
35283530 }
35293531 }
3530− });
3531− let popup =
3532− Popup::new("code-action", picker).margin(helix_view::graphics::Margin {
3533− vertical: 1,
3534− horizontal: 1,
3535− });
3536− compositor.push(Box::new(popup))
3537− }
3532+ }
3533+ });
3534+ let popup = Popup::new("code-action", picker).margin(helix_view::graphics::Margin {
3535+ vertical: 1,
3536+ horizontal: 1,
3537+ });
3538+ compositor.push(Box::new(popup))
35383539 },
35393540 )
35403541}