From 616d328f3c3423ce6c62e44ddabfeb66e0294b3e Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 18 Sep 2023 17:01:08 +0200 Subject: [PATCH] chore: Use aho-corasick 1.1 in direct dependencies (#2983) Nothing too fancy, we've depended indirectly on 1.0/1.1 already, so this is essentially bookkeeping. Release Notes: - N/A --- Cargo.lock | 23 ++++-------- crates/collab/src/tests/integration_tests.rs | 2 +- .../random_project_collaboration_tests.rs | 2 +- crates/editor/Cargo.toml | 2 +- crates/editor/src/editor.rs | 22 +++++++----- crates/editor/src/editor_tests.rs | 36 ++++++++++++------- crates/project/Cargo.toml | 2 +- crates/project/src/project_tests.rs | 35 ++++++++++-------- crates/project/src/search.rs | 15 ++++---- crates/search/src/buffer_search.rs | 13 +++++-- crates/search/src/project_search.rs | 14 ++++++-- 11 files changed, 99 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b77ff20af3..c620cb2b88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,18 +79,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - -[[package]] -name = "aho-corasick" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "0f2135563fb5c609d2b2b87c1e8ce7bc41b0b45430fa9661f457981503dd5bf0" dependencies = [ "memchr", ] @@ -2332,7 +2323,7 @@ checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" name = "editor" version = "0.1.0" dependencies = [ - "aho-corasick 0.7.20", + "aho-corasick", "anyhow", "client", "clock", @@ -3080,7 +3071,7 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" dependencies = [ - "aho-corasick 1.0.4", + "aho-corasick", "bstr", "fnv", "log", @@ -5462,7 +5453,7 @@ dependencies = [ name = "project" version = "0.1.0" dependencies = [ - "aho-corasick 0.7.20", + "aho-corasick", "anyhow", "async-trait", "backtrace", @@ -5972,7 +5963,7 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" dependencies = [ - "aho-corasick 1.0.4", + "aho-corasick", "memchr", "regex-automata 0.3.6", "regex-syntax 0.7.4", @@ -5993,7 +5984,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" dependencies = [ - "aho-corasick 1.0.4", + "aho-corasick", "memchr", "regex-syntax 0.7.4", ] diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index a9f4a31eb7..10d6baec19 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -4825,7 +4825,7 @@ async fn test_project_search( let mut results = HashMap::default(); let mut search_rx = project_b.update(cx_b, |project, cx| { project.search( - SearchQuery::text("world", false, false, Vec::new(), Vec::new()), + SearchQuery::text("world", false, false, Vec::new(), Vec::new()).unwrap(), cx, ) }); diff --git a/crates/collab/src/tests/random_project_collaboration_tests.rs b/crates/collab/src/tests/random_project_collaboration_tests.rs index 7570768249..6f9513c325 100644 --- a/crates/collab/src/tests/random_project_collaboration_tests.rs +++ b/crates/collab/src/tests/random_project_collaboration_tests.rs @@ -869,7 +869,7 @@ impl RandomizedTest for ProjectCollaborationTest { let mut search = project.update(cx, |project, cx| { project.search( - SearchQuery::text(query, false, false, Vec::new(), Vec::new()), + SearchQuery::text(query, false, false, Vec::new(), Vec::new()).unwrap(), cx, ) }); diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 2fdeee56c1..b0f8323a76 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -45,7 +45,7 @@ util = { path = "../util" } sqlez = { path = "../sqlez" } workspace = { path = "../workspace" } -aho-corasick = "0.7" +aho-corasick = "1.1" anyhow.workspace = true convert_case = "0.6.0" futures.workspace = true diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b36cf9f71d..8c30859841 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5936,7 +5936,7 @@ impl Editor { } } - pub fn select_next(&mut self, action: &SelectNext, cx: &mut ViewContext) { + pub fn select_next(&mut self, action: &SelectNext, cx: &mut ViewContext) -> Result<()> { self.push_to_selection_history(); let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); let buffer = &display_map.buffer_snapshot; @@ -6005,7 +6005,7 @@ impl Editor { .text_for_range(selection.start..selection.end) .collect::(); let select_state = SelectNextState { - query: AhoCorasick::new_auto_configured(&[query]), + query: AhoCorasick::new(&[query])?, wordwise: true, done: false, }; @@ -6019,16 +6019,21 @@ impl Editor { .text_for_range(selection.start..selection.end) .collect::(); self.select_next_state = Some(SelectNextState { - query: AhoCorasick::new_auto_configured(&[query]), + query: AhoCorasick::new(&[query])?, wordwise: false, done: false, }); - self.select_next(action, cx); + self.select_next(action, cx)?; } } + Ok(()) } - pub fn select_previous(&mut self, action: &SelectPrevious, cx: &mut ViewContext) { + pub fn select_previous( + &mut self, + action: &SelectPrevious, + cx: &mut ViewContext, + ) -> Result<()> { self.push_to_selection_history(); let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); let buffer = &display_map.buffer_snapshot; @@ -6099,7 +6104,7 @@ impl Editor { .collect::(); let query = query.chars().rev().collect::(); let select_state = SelectNextState { - query: AhoCorasick::new_auto_configured(&[query]), + query: AhoCorasick::new(&[query])?, wordwise: true, done: false, }; @@ -6114,13 +6119,14 @@ impl Editor { .collect::(); let query = query.chars().rev().collect::(); self.select_prev_state = Some(SelectNextState { - query: AhoCorasick::new_auto_configured(&[query]), + query: AhoCorasick::new(&[query])?, wordwise: false, done: false, }); - self.select_previous(action, cx); + self.select_previous(action, cx)?; } } + Ok(()) } pub fn toggle_comments(&mut self, action: &ToggleComments, cx: &mut ViewContext) { diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index f11639a770..7acf0c652f 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -3669,10 +3669,12 @@ async fn test_select_next(cx: &mut gpui::TestAppContext) { let mut cx = EditorTestContext::new(cx).await; cx.set_state("abc\nˇabc abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)); + cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)) + .unwrap(); cx.assert_editor_state("abc\n«abcˇ» abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)); + cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)) + .unwrap(); cx.assert_editor_state("abc\n«abcˇ» «abcˇ»\ndefabc\nabc"); cx.update_editor(|view, cx| view.undo_selection(&UndoSelection, cx)); @@ -3681,10 +3683,12 @@ async fn test_select_next(cx: &mut gpui::TestAppContext) { cx.update_editor(|view, cx| view.redo_selection(&RedoSelection, cx)); cx.assert_editor_state("abc\n«abcˇ» «abcˇ»\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)); + cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)) + .unwrap(); cx.assert_editor_state("abc\n«abcˇ» «abcˇ»\ndefabc\n«abcˇ»"); - cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)); + cx.update_editor(|e, cx| e.select_next(&SelectNext::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«abcˇ» «abcˇ»\ndefabc\n«abcˇ»"); } @@ -3696,10 +3700,12 @@ async fn test_select_previous(cx: &mut gpui::TestAppContext) { let mut cx = EditorTestContext::new(cx).await; cx.set_state("abc\nˇabc abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("abc\n«abcˇ» abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«abcˇ» abc\ndefabc\nabc"); cx.update_editor(|view, cx| view.undo_selection(&UndoSelection, cx)); @@ -3708,10 +3714,12 @@ async fn test_select_previous(cx: &mut gpui::TestAppContext) { cx.update_editor(|view, cx| view.redo_selection(&RedoSelection, cx)); cx.assert_editor_state("«abcˇ»\n«abcˇ» abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«abcˇ» abc\ndefabc\n«abcˇ»"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«abcˇ» «abcˇ»\ndefabc\n«abcˇ»"); } { @@ -3719,10 +3727,12 @@ async fn test_select_previous(cx: &mut gpui::TestAppContext) { let mut cx = EditorTestContext::new(cx).await; cx.set_state("abc\n«ˇabc» abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«ˇabc» abc\ndefabc\nabc"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«ˇabc» abc\ndefabc\n«abcˇ»"); cx.update_editor(|view, cx| view.undo_selection(&UndoSelection, cx)); @@ -3731,10 +3741,12 @@ async fn test_select_previous(cx: &mut gpui::TestAppContext) { cx.update_editor(|view, cx| view.redo_selection(&RedoSelection, cx)); cx.assert_editor_state("«abcˇ»\n«ˇabc» abc\ndefabc\n«abcˇ»"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«ˇabc» abc\ndef«abcˇ»\n«abcˇ»"); - cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)); + cx.update_editor(|e, cx| e.select_previous(&SelectPrevious::default(), cx)) + .unwrap(); cx.assert_editor_state("«abcˇ»\n«ˇabc» «abcˇ»\ndef«abcˇ»\n«abcˇ»"); } } diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index bfe5f89f68..0dc76ed54a 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -37,7 +37,7 @@ sum_tree = { path = "../sum_tree" } terminal = { path = "../terminal" } util = { path = "../util" } -aho-corasick = "0.7" +aho-corasick = "1.1" anyhow.workspace = true async-trait.workspace = true backtrace = "0.3" diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index b6adb371e1..540915f354 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -3598,7 +3598,7 @@ async fn test_search(cx: &mut gpui::TestAppContext) { assert_eq!( search( &project, - SearchQuery::text("TWO", false, true, Vec::new(), Vec::new()), + SearchQuery::text("TWO", false, true, Vec::new(), Vec::new()).unwrap(), cx ) .await @@ -3623,7 +3623,7 @@ async fn test_search(cx: &mut gpui::TestAppContext) { assert_eq!( search( &project, - SearchQuery::text("TWO", false, true, Vec::new(), Vec::new()), + SearchQuery::text("TWO", false, true, Vec::new(), Vec::new()).unwrap(), cx ) .await @@ -3664,7 +3664,8 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { true, vec![PathMatcher::new("*.odd").unwrap()], Vec::new() - ), + ) + .unwrap(), cx ) .await @@ -3682,7 +3683,8 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { true, vec![PathMatcher::new("*.rs").unwrap()], Vec::new() - ), + ) + .unwrap(), cx ) .await @@ -3706,7 +3708,7 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { PathMatcher::new("*.odd").unwrap(), ], Vec::new() - ), + ).unwrap(), cx ) .await @@ -3731,7 +3733,7 @@ async fn test_search_with_inclusions(cx: &mut gpui::TestAppContext) { PathMatcher::new("*.odd").unwrap(), ], Vec::new() - ), + ).unwrap(), cx ) .await @@ -3774,7 +3776,8 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { true, Vec::new(), vec![PathMatcher::new("*.odd").unwrap()], - ), + ) + .unwrap(), cx ) .await @@ -3797,7 +3800,8 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { true, Vec::new(), vec![PathMatcher::new("*.rs").unwrap()], - ), + ) + .unwrap(), cx ) .await @@ -3821,7 +3825,7 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { PathMatcher::new("*.ts").unwrap(), PathMatcher::new("*.odd").unwrap(), ], - ), + ).unwrap(), cx ) .await @@ -3846,7 +3850,7 @@ async fn test_search_with_exclusions(cx: &mut gpui::TestAppContext) { PathMatcher::new("*.ts").unwrap(), PathMatcher::new("*.odd").unwrap(), ], - ), + ).unwrap(), cx ) .await @@ -3883,7 +3887,8 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex true, vec![PathMatcher::new("*.odd").unwrap()], vec![PathMatcher::new("*.odd").unwrap()], - ), + ) + .unwrap(), cx ) .await @@ -3901,7 +3906,7 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex true, vec![PathMatcher::new("*.ts").unwrap()], vec![PathMatcher::new("*.ts").unwrap()], - ), + ).unwrap(), cx ) .await @@ -3925,7 +3930,8 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex PathMatcher::new("*.ts").unwrap(), PathMatcher::new("*.odd").unwrap() ], - ), + ) + .unwrap(), cx ) .await @@ -3949,7 +3955,8 @@ async fn test_search_with_exclusions_and_inclusions(cx: &mut gpui::TestAppContex PathMatcher::new("*.rs").unwrap(), PathMatcher::new("*.odd").unwrap() ], - ), + ) + .unwrap(), cx ) .await diff --git a/crates/project/src/search.rs b/crates/project/src/search.rs index bf81158701..663ad46123 100644 --- a/crates/project/src/search.rs +++ b/crates/project/src/search.rs @@ -35,7 +35,7 @@ impl SearchInputs { #[derive(Clone, Debug)] pub enum SearchQuery { Text { - search: Arc>, + search: Arc, replacement: Option, whole_word: bool, case_sensitive: bool, @@ -84,24 +84,23 @@ impl SearchQuery { case_sensitive: bool, files_to_include: Vec, files_to_exclude: Vec, - ) -> Self { + ) -> Result { let query = query.to_string(); let search = AhoCorasickBuilder::new() - .auto_configure(&[&query]) .ascii_case_insensitive(!case_sensitive) - .build(&[&query]); + .build(&[&query])?; let inner = SearchInputs { query: query.into(), files_to_exclude, files_to_include, }; - Self::Text { + Ok(Self::Text { search: Arc::new(search), replacement: None, whole_word, case_sensitive, inner, - } + }) } pub fn regex( @@ -151,13 +150,13 @@ impl SearchQuery { deserialize_path_matches(&message.files_to_exclude)?, ) } else { - Ok(Self::text( + Self::text( message.query, message.whole_word, message.case_sensitive, deserialize_path_matches(&message.files_to_include)?, deserialize_path_matches(&message.files_to_exclude)?, - )) + ) } } pub fn with_replacement(mut self, new_replacement: Option) -> Self { diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index bf92c2b72e..5fc0854b81 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -783,14 +783,21 @@ impl BufferSearchBar { } } } else { - SearchQuery::text( + match SearchQuery::text( query, self.search_options.contains(SearchOptions::WHOLE_WORD), self.search_options.contains(SearchOptions::CASE_SENSITIVE), Vec::new(), Vec::new(), - ) - .with_replacement(Some(self.replacement(cx)).filter(|s| !s.is_empty())) + ) { + Ok(query) => query + .with_replacement(Some(self.replacement(cx)).filter(|s| !s.is_empty())), + Err(_) => { + self.query_contains_error = true; + cx.notify(); + return done_rx; + } + } } .into(); self.active_search = Some(query.clone()); diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 240928d4e0..1944219117 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1050,13 +1050,23 @@ impl ProjectSearchView { } } } - _ => Some(SearchQuery::text( + _ => match SearchQuery::text( text, self.search_options.contains(SearchOptions::WHOLE_WORD), self.search_options.contains(SearchOptions::CASE_SENSITIVE), included_files, excluded_files, - )), + ) { + Ok(query) => { + self.panels_with_errors.remove(&InputPanel::Query); + Some(query) + } + Err(_e) => { + self.panels_with_errors.insert(InputPanel::Query); + cx.notify(); + None + } + }, } }