on master help sign in
Reformat with nightly rustfmt for better let-else formatting (#7721)
8a28f30Philipp Mildenberger
helix-core/src/match_brackets.rs+6−2
@@ -106,12 +106,16 @@ fn find_pair(
106 for close in
106 for close in
107 iter::successors(node.next_sibling(), |node| node.next_sibling()).take(MATCH_LIMIT)
107 iter::successors(node.next_sibling(), |node| node.next_sibling()).take(MATCH_LIMIT)
108 {
108 {
109− let Some(open) = as_close_pair(doc, &close) else { continue; };
109+ let Some(open) = as_close_pair(doc, &close) else {
110+ continue;
111+ };
110 if find_pair_end(doc, Some(node), open, Backward).is_some() {
112 if find_pair_end(doc, Some(node), open, Backward).is_some() {
111 return doc.try_byte_to_char(close.start_byte()).ok();
113 return doc.try_byte_to_char(close.start_byte()).ok();
112 }
114 }
113 }
115 }
114− let Some(parent) = node.parent() else { break; };
116+ let Some(parent) = node.parent() else {
117+ break;
118+ };
115 node = parent;
119 node = parent;
116 }
120 }
117 let node = tree.root_node().named_descendant_for_byte_range(pos, pos)?;
121 let node = tree.root_node().named_descendant_for_byte_range(pos, pos)?;
helix-core/src/transaction.rs+4−1
@@ -389,7 +389,10 @@ impl ChangeSet {
389 }
389 }
390
390
391 let Some((i, change)) = iter.next() else {
391 let Some((i, change)) = iter.next() else {
392+ map!(
392− map!(|pos, _| (old_pos == pos).then_some(new_pos), self.changes.len());
393+ |pos, _| (old_pos == pos).then_some(new_pos),
394+ self.changes.len()
395+ );
393 break;
396 break;
394 };
397 };
395
398
helix-loader/build.rs+6−2
@@ -40,7 +40,9 @@ fn main() {
40 .ok()
40 .ok()
41 .filter(|output| output.status.success())
41 .filter(|output| output.status.success())
42 .and_then(|x| String::from_utf8(x.stdout).ok())
42 .and_then(|x| String::from_utf8(x.stdout).ok())
43+ else {
43− else{ return; };
44+ return;
45+ };
44 // If heads starts pointing at something else (different branch)
46 // If heads starts pointing at something else (different branch)
45 // we need to return
47 // we need to return
46 let head = Path::new(&git_dir).join("HEAD");
48 let head = Path::new(&git_dir).join("HEAD");
@@ -55,7 +57,9 @@ fn main() {
55 .ok()
57 .ok()
56 .filter(|output| output.status.success())
58 .filter(|output| output.status.success())
57 .and_then(|x| String::from_utf8(x.stdout).ok())
59 .and_then(|x| String::from_utf8(x.stdout).ok())
60+ else {
58− else{ return; };
61+ return;
62+ };
59 let head_ref = Path::new(&git_dir).join(head_ref);
63 let head_ref = Path::new(&git_dir).join(head_ref);
60 if head_ref.exists() {
64 if head_ref.exists() {
61 println!("cargo:rerun-if-changed={}", head_ref.display());
65 println!("cargo:rerun-if-changed={}", head_ref.display());
helix-lsp/src/lib.rs+1−1
@@ -435,7 +435,7 @@ pub mod util {
435 }
435 }
436
436
437 let tabstops = tabstops.first().filter(|tabstops| !tabstops.is_empty());
437 let tabstops = tabstops.first().filter(|tabstops| !tabstops.is_empty());
438− let Some(tabstops) = tabstops else{
438+ let Some(tabstops) = tabstops else {
439 // no tabstop normal mapping
439 // no tabstop normal mapping
440 mapped_selection.push(range);
440 mapped_selection.push(range);
441 continue;
441 continue;
helix-term/src/commands/lsp.rs+14−6
@@ -730,7 +730,8 @@ pub fn code_action(cx: &mut Context) {
730
730
731 // always present here
731 // always present here
732 let action = action.unwrap();
732 let action = action.unwrap();
733− let Some(language_server) = editor.language_server_by_id(action.language_server_id) else {
733+ let Some(language_server) = editor.language_server_by_id(action.language_server_id)
734+ else {
734 editor.set_error("Language Server disappeared");
735 editor.set_error("Language Server disappeared");
735 return;
736 return;
736 };
737 };
@@ -746,15 +747,20 @@ pub fn code_action(cx: &mut Context) {
746 // we support lsp "codeAction/resolve" for `edit` and `command` fields
747 // we support lsp "codeAction/resolve" for `edit` and `command` fields
747 let mut resolved_code_action = None;
748 let mut resolved_code_action = None;
748 if code_action.edit.is_none() || code_action.command.is_none() {
749 if code_action.edit.is_none() || code_action.command.is_none() {
750+ if let Some(future) =
749− if let Some(future) = language_server.resolve_code_action(code_action.clone()) {
751+ language_server.resolve_code_action(code_action.clone())
752+ {
750 if let Ok(response) = helix_lsp::block_on(future) {
753 if let Ok(response) = helix_lsp::block_on(future) {
754+ if let Ok(code_action) =
751− if let Ok(code_action) = serde_json::from_value::<CodeAction>(response) {
755+ serde_json::from_value::<CodeAction>(response)
756+ {
752 resolved_code_action = Some(code_action);
757 resolved_code_action = Some(code_action);
753 }
758 }
754 }
759 }
755 }
760 }
756 }
761 }
762+ let resolved_code_action =
757− let resolved_code_action = resolved_code_action.as_ref().unwrap_or(code_action);
763+ resolved_code_action.as_ref().unwrap_or(code_action);
758
764
759 if let Some(ref workspace_edit) = resolved_code_action.edit {
765 if let Some(ref workspace_edit) = resolved_code_action.edit {
760 log::debug!("edit: {:?}", workspace_edit);
766 log::debug!("edit: {:?}", workspace_edit);
@@ -1186,7 +1192,8 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) {
1186 // Do not show the message if signature help was invoked
1192 // Do not show the message if signature help was invoked
1187 // automatically on backspace, trigger characters, etc.
1193 // automatically on backspace, trigger characters, etc.
1188 if invoked == SignatureHelpInvoked::Manual {
1194 if invoked == SignatureHelpInvoked::Manual {
1195+ cx.editor
1189− cx.editor.set_error("No configured language server supports signature-help");
1196+ .set_error("No configured language server supports signature-help");
1190 }
1197 }
1191 return;
1198 return;
1192 };
1199 };
@@ -1411,7 +1418,8 @@ pub fn rename_symbol(cx: &mut Context) {
1411 .language_servers_with_feature(LanguageServerFeature::RenameSymbol)
1418 .language_servers_with_feature(LanguageServerFeature::RenameSymbol)
1412 .find(|ls| language_server_id.map_or(true, |id| id == ls.id()))
1419 .find(|ls| language_server_id.map_or(true, |id| id == ls.id()))
1413 else {
1420 else {
1421+ cx.editor
1414− cx.editor.set_error("No configured language server supports symbol renaming");
1422+ .set_error("No configured language server supports symbol renaming");
1415 return;
1423 return;
1416 };
1424 };
1417
1425
helix-term/src/commands/typed.rs+2−3
@@ -1385,9 +1385,8 @@ fn lsp_workspace_command(
1385 .map(|options| (ls.id(), options))
1385 .map(|options| (ls.id(), options))
1386 })
1386 })
1387 else {
1387 else {
1388− cx.editor.set_status(
1388+ cx.editor
1389− "No active language servers for this document support workspace commands",
1389+ .set_status("No active language servers for this document support workspace commands");
1390− );
1391 return Ok(());
1390 return Ok(());
1392 };
1391 };
1393
1392
helix-term/src/ui/completion.rs+13−3
@@ -144,7 +144,9 @@ impl Completion {
144 }
144 }
145 };
145 };
146
146
147+ let Some(range) =
147− let Some(range) = util::lsp_range_to_range(doc.text(), edit.range, offset_encoding) else{
148+ util::lsp_range_to_range(doc.text(), edit.range, offset_encoding)
149+ else {
148 return Transaction::new(doc.text());
150 return Transaction::new(doc.text());
149 };
151 };
150
152
@@ -413,10 +415,18 @@ impl Completion {
413 _ => return false,
415 _ => return false,
414 };
416 };
415
417
418+ let Some(language_server) = cx
419+ .editor
416− let Some(language_server) = cx.editor.language_server_by_id(current_item.language_server_id) else { return false; };
420+ .language_server_by_id(current_item.language_server_id)
421+ else {
422+ return false;
423+ };
417
424
418 // This method should not block the compositor so we handle the response asynchronously.
425 // This method should not block the compositor so we handle the response asynchronously.
419− let Some(future) = language_server.resolve_completion_item(current_item.item.clone()) else { return false; };
426+ let Some(future) = language_server.resolve_completion_item(current_item.item.clone())
427+ else {
428+ return false;
429+ };
420
430
421 cx.callback(
431 cx.callback(
422 future,
432 future,
helix-term/src/ui/picker.rs+7−4
@@ -432,7 +432,7 @@ impl<T: Item + 'static> Picker<T> {
432
432
433 fn handle_idle_timeout(&mut self, cx: &mut Context) -> EventResult {
433 fn handle_idle_timeout(&mut self, cx: &mut Context) -> EventResult {
434 let Some((current_file, _)) = self.current_file(cx.editor) else {
434 let Some((current_file, _)) = self.current_file(cx.editor) else {
435− return EventResult::Consumed(None)
435+ return EventResult::Consumed(None);
436 };
436 };
437
437
438 // Try to find a document in the cache
438 // Try to find a document in the cache
@@ -459,11 +459,14 @@ impl<T: Item + 'static> Picker<T> {
459 let callback = move |editor: &mut Editor, compositor: &mut Compositor| {
459 let callback = move |editor: &mut Editor, compositor: &mut Compositor| {
460 let Some(syntax) = syntax else {
460 let Some(syntax) = syntax else {
461 log::info!("highlighting picker item failed");
461 log::info!("highlighting picker item failed");
462− return
462+ return;
463 };
463 };
464+ let Some(Overlay {
465+ content: picker, ..
464− let Some(Overlay { content: picker, .. }) = compositor.find::<Overlay<Self>>() else {
466+ }) = compositor.find::<Overlay<Self>>()
467+ else {
465 log::info!("picker closed before syntax highlighting finished");
468 log::info!("picker closed before syntax highlighting finished");
466− return
469+ return;
467 };
470 };
468 // Try to find a document in the cache
471 // Try to find a document in the cache
469 let doc = match current_file {
472 let doc = match current_file {