From 1849ad1fdee8e19622b419e3a1a3643b4fcd7f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Wed, 23 Mar 2022 16:55:42 +0900 Subject: [PATCH] Clean up global search --- helix-term/src/commands.rs | 48 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 01d20b285..4b4e834a5 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1712,39 +1712,37 @@ fn global_search(cx: &mut Context) { .max_depth(file_picker_config.max_depth) .build_parallel() .run(|| { - let mut searcher_cl = searcher.clone(); - let matcher_cl = matcher.clone(); - let all_matches_sx_cl = all_matches_sx.clone(); - Box::new(move |dent: Result| -> WalkState { - let dent = match dent { - Ok(dent) => dent, + let mut searcher = searcher.clone(); + let matcher = matcher.clone(); + let all_matches_sx = all_matches_sx.clone(); + Box::new(move |entry: Result| -> WalkState { + let entry = match entry { + Ok(entry) => entry, Err(_) => return WalkState::Continue, }; - match dent.file_type() { - Some(fi) => { - if !fi.is_file() { - return WalkState::Continue; - } - } - None => return WalkState::Continue, - } + match entry.file_type() { + Some(entry) if entry.is_file() => {} + // skip everything else + _ => return WalkState::Continue, + }; - let result_sink = sinks::UTF8(|line_num, _| { - match all_matches_sx_cl - .send((line_num as usize - 1, dent.path().to_path_buf())) - { - Ok(_) => Ok(true), - Err(_) => Ok(false), - } - }); - let result = - searcher_cl.search_path(&matcher_cl, dent.path(), result_sink); + let result = searcher.search_path( + &matcher, + entry.path(), + sinks::UTF8(|line_num, _| { + all_matches_sx + .send((line_num as usize - 1, entry.path().to_path_buf())) + .unwrap(); + + Ok(true) + }), + ); if let Err(err) = result { log::error!( "Global search error: {}, {}", - dent.path().display(), + entry.path().display(), err ); }