aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGokul Soumya2022-02-07 16:01:11 +0000
committerBlaž Hrastnik2022-02-08 07:44:39 +0000
commite90276df0b7a643e6fa8a7bb61a21d93c57383ef (patch)
tree81bce637a94cdf49548c38f4e269e773b7409dd3
parentf0cd02d5ef90e549e5e9f5dfce1d2317ad978b72 (diff)
Replace if let with early return
-rw-r--r--helix-term/src/commands.rs67
1 files changed, 34 insertions, 33 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 6bc2b9b6..9b98e6c4 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -3494,47 +3494,48 @@ pub fn code_action(cx: &mut Context) {
move |editor: &mut Editor,
compositor: &mut Compositor,
response: Option<lsp::CodeActionResponse>| {
- if let Some(actions) = response {
- if actions.is_empty() {
- editor.set_status("No code actions available".to_owned());
+ let actions = match response {
+ Some(a) => a,
+ None => return,
+ };
+ if actions.is_empty() {
+ editor.set_status("No code actions available".to_owned());
+ return;
+ }
+
+ let picker = ui::Menu::new(actions, move |editor, code_action, event| {
+ if event != PromptEvent::Validate {
return;
}
- let picker = ui::Menu::new(actions, move |editor, code_action, event| {
- if event != PromptEvent::Validate {
- return;
- }
-
- // always present here
- let code_action = code_action.unwrap();
+ // always present here
+ let code_action = code_action.unwrap();
- match code_action {
- lsp::CodeActionOrCommand::Command(command) => {
- log::debug!("code action command: {:?}", command);
- execute_lsp_command(editor, command.clone());
+ match code_action {
+ lsp::CodeActionOrCommand::Command(command) => {
+ log::debug!("code action command: {:?}", command);
+ execute_lsp_command(editor, command.clone());
+ }
+ lsp::CodeActionOrCommand::CodeAction(code_action) => {
+ log::debug!("code action: {:?}", code_action);
+ if let Some(ref workspace_edit) = code_action.edit {
+ log::debug!("edit: {:?}", workspace_edit);
+ apply_workspace_edit(editor, offset_encoding, workspace_edit);
}
- lsp::CodeActionOrCommand::CodeAction(code_action) => {
- log::debug!("code action: {:?}", code_action);
- if let Some(ref workspace_edit) = code_action.edit {
- log::debug!("edit: {:?}", workspace_edit);
- apply_workspace_edit(editor, offset_encoding, workspace_edit);
- }
- // if code action provides both edit and command first the edit
- // should be applied and then the command
- if let Some(command) = &code_action.command {
- execute_lsp_command(editor, command.clone());
- }
+ // if code action provides both edit and command first the edit
+ // should be applied and then the command
+ if let Some(command) = &code_action.command {
+ execute_lsp_command(editor, command.clone());
}
}
- });
- let popup =
- Popup::new("code-action", picker).margin(helix_view::graphics::Margin {
- vertical: 1,
- horizontal: 1,
- });
- compositor.push(Box::new(popup))
- }
+ }
+ });
+ let popup = Popup::new("code-action", picker).margin(helix_view::graphics::Margin {
+ vertical: 1,
+ horizontal: 1,
+ });
+ compositor.push(Box::new(popup))
},
)
}