on master help sign in
Replace if let with early return
e90276dGokul Soumya
helix-term/src/commands.rs+34−33
@@ -3494,47 +3494,48 @@ pub fn code_action(cx: &mut Context) {
3494 move |editor: &mut Editor,
3494 move |editor: &mut Editor,
3495 compositor: &mut Compositor,
3495 compositor: &mut Compositor,
3496 response: Option<lsp::CodeActionResponse>| {
3496 response: Option<lsp::CodeActionResponse>| {
3497− if let Some(actions) = response {
3497+ let actions = match response {
3498+ Some(a) => a,
3499+ None => return,
3500+ };
3498− if actions.is_empty() {
3501+ if actions.is_empty() {
3499− editor.set_status("No code actions available".to_owned());
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 {
3500 return;
3508 return;
3501 }
3509 }
3502
3510
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
3511+ // always present here
3509− let code_action = code_action.unwrap();
3512+ let code_action = code_action.unwrap();
3510
3513
3511− match code_action {
3514+ match code_action {
3512− lsp::CodeActionOrCommand::Command(command) => {
3515+ lsp::CodeActionOrCommand::Command(command) => {
3513− log::debug!("code action command: {:?}", command);
3516+ log::debug!("code action command: {:?}", command);
3514− execute_lsp_command(editor, command.clone());
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);
3515 }
3524 }
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− }
3522
3525
3523− // if code action provides both edit and command first the edit
3526+ // if code action provides both edit and command first the edit
3524− // should be applied and then the command
3527+ // should be applied and then the command
3525− if let Some(command) = &code_action.command {
3528+ if let Some(command) = &code_action.command {
3526− execute_lsp_command(editor, command.clone());
3529+ execute_lsp_command(editor, command.clone());
3527− }
3528 }
3530 }
3529 }
3531 }
3532+ }
3530− });
3533+ });
3531− let popup =
3532− Popup::new("code-action", picker).margin(helix_view::graphics::Margin {
3534+ let popup = Popup::new("code-action", picker).margin(helix_view::graphics::Margin {
3533− vertical: 1,
3535+ vertical: 1,
3534− horizontal: 1,
3536+ horizontal: 1,
3535− });
3537+ });
3536− compositor.push(Box::new(popup))
3538+ compositor.push(Box::new(popup))
3537− }
3538 },
3539 },
3539 )
3540 )
3540}
3541}