From b8727f78c7d218405921e09fc68bc3f5bee7b558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 11:59:54 +0200 Subject: [PATCH 01/60] WIP todo --- app/gui/src/controller/searcher/component/builder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 80255c824547..6068adf25e23 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -135,6 +135,7 @@ impl List { .filter_map(|g| component::Group::from_execution_context_component_group(g, db)) .collect(); for group in &*self.favorites { + // TODO[MC]: can we delete this code, due to only showing IDs of completions returned by Engine? self.all_components.extend(group.entries.borrow().iter().cloned()); } } From 07c0d7137fcdd7f290bace25c96239b69a8558db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 12:05:33 +0200 Subject: [PATCH 02/60] WIP add components_by_id field --- app/gui/src/controller/searcher/component/builder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 6068adf25e23..5ba9039add07 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -66,6 +66,7 @@ impl ModuleGroups { #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, + components_by_id: HashMap, module_groups: HashMap, local_scope: component::Group, favorites: component::group::List, From b60c77d608f0aef3a6b06f91efd77f45a6ffea57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 12:05:39 +0200 Subject: [PATCH 03/60] WIP another TODO --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 5ba9039add07..50b777fc4b68 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -65,7 +65,7 @@ impl ModuleGroups { /// groups. #[derive(Clone, Debug, Default)] pub struct List { - all_components: Vec, + all_components: Vec, // TODO[MC]: only keep component IDs at this stage? components_by_id: HashMap, module_groups: HashMap, local_scope: component::Group, From 50d9f27e59cb6fa8c6beee51f2a46ce027e0706b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 12:15:20 +0200 Subject: [PATCH 04/60] WIP store component IDs --- app/gui/src/controller/searcher/component/builder.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 50b777fc4b68..45980415458c 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -66,7 +66,8 @@ impl ModuleGroups { #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, // TODO[MC]: only keep component IDs at this stage? - components_by_id: HashMap, + // TODO[MC]: use HashMap + component_ids: HashSet, module_groups: HashMap, local_scope: component::Group, favorites: component::group::List, @@ -100,6 +101,7 @@ impl List { let lookup_component_by_id = |id| Some(Component::new(id, db.lookup(id).ok()?)); let components = entries.into_iter().filter_map(lookup_component_by_id); for component in components { + self.component_ids.insert(*component.id); let mut component_inserted_somewhere = false; if let Some(parent_module) = component.suggestion.parent_module() { if let Some(parent_group) = self.lookup_module_group(db, &parent_module) { From ee4d7253a15c99de0080b48a5bebfdcbce640565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 12:26:24 +0200 Subject: [PATCH 05/60] WIP filtered_favorites() --- app/gui/src/controller/searcher/component/builder.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 45980415458c..563ceaea4212 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -184,6 +184,7 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); + let favorites = self.filtered_favorites(); component::List { all_components: Rc::new(self.all_components), top_modules: top_mdl_bld.build(), @@ -193,9 +194,14 @@ impl List { ), local_scope: self.local_scope, filtered: default(), - favorites: self.favorites, + favorites, } } + + fn filtered_favorites(&self) -> component::group::List { + let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); + component::group::List::new(filtered_groups) + } } From 82aab628c0d161002813e35ce4f02e2bacd8ea46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 12:51:11 +0200 Subject: [PATCH 06/60] WIP filter_favorites() --- .../src/controller/searcher/component/builder.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 563ceaea4212..4cbb78cdcd59 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -184,7 +184,7 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); - let favorites = self.filtered_favorites(); + self.filter_favorites(); component::List { all_components: Rc::new(self.all_components), top_modules: top_mdl_bld.build(), @@ -194,13 +194,17 @@ impl List { ), local_scope: self.local_scope, filtered: default(), - favorites, + favorites: self.favorites, } } - fn filtered_favorites(&self) -> component::group::List { - let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); - component::group::List::new(filtered_groups) + fn filter_favorites(&self) { + // // TODO[MC}: consider refactoring to functional + // let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); + for group in &*self.favorites { + group.entries.borrow_mut().retain(|c| self.component_ids.contains(&c.id)); + } + // component::group::List::new(filtered_groups) } } From 6d3dfdeb3094e2b6ef456f527d417c265ccf29c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 12:51:25 +0200 Subject: [PATCH 07/60] CLEANUP some comments --- app/gui/src/controller/searcher/component/builder.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 4cbb78cdcd59..4bd35c6de8d8 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -199,12 +199,9 @@ impl List { } fn filter_favorites(&self) { - // // TODO[MC}: consider refactoring to functional - // let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); for group in &*self.favorites { group.entries.borrow_mut().retain(|c| self.component_ids.contains(&c.id)); } - // component::group::List::new(filtered_groups) } } From 254fd0ec7d4ddaaa650b1a943dc096679cdd6a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 15:20:25 +0200 Subject: [PATCH 08/60] sketch of test --- .../controller/searcher/component/builder.rs | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 4bd35c6de8d8..554ca16499f0 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -184,7 +184,7 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); - self.filter_favorites(); + self.retain_favorites(); component::List { all_components: Rc::new(self.all_components), top_modules: top_mdl_bld.build(), @@ -198,7 +198,7 @@ impl List { } } - fn filter_favorites(&self) { + fn retain_favorites(&self) { for group in &*self.favorites { group.entries.borrow_mut().retain(|c| self.component_ids.contains(&c.id)); } @@ -337,4 +337,44 @@ mod tests { let expected_ids = vec![5, 6]; assert_eq!(local_scope_ids, expected_ids); } + + #[test] + fn building_component_list_with_favorites() { + let logger = Logger::new("tests::building_component_list_with_favorites"); + let suggestion_db = mock_suggestion_db(logger); + let mut builder = List::new(); + let completion_ids = [0, 1, 2]; + const SUGGESTION_NAME_NOT_IN_DB: &str = "test.Test.NameNotInSuggestionDb"; + const SUGGESTION_NAME_NOT_IN_COMPLETION_IDS: &str = "test.Test.TopModule1.fun1"; + const SUGGESTION_NAME_IN_COMPLETION_IDS: &str = "test.Test.TopModule1"; + let groups = [ + execution_context::ComponentGroup { + name: "Group 1".into(), + color: None, + components: vec![ + SUGGESTION_NAME_IN_COMPLETION_IDS.into(), + SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), + SUGGESTION_NAME_NOT_IN_DB.into(), + SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), + SUGGESTION_NAME_NOT_IN_DB.into(), + SUGGESTION_NAME_IN_COMPLETION_IDS.into(), + ], + }, + execution_context::ComponentGroup { + name: "Group with items not in DB and not in completions".into(), + name: "Group with items not in DB".into(), + color: None, + components: vec![ + SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), + SUGGESTION_NAME_NOT_IN_DB.into(), + SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), + SUGGESTION_NAME_NOT_IN_DB.into(), + ], + }, + ]; + builder.set_favorites(&suggestion_db, groups); + builder.extend(&suggestion_db, &completion_ids); + let list = builder.build(); + let favorites: Vec = list.favorites.iter().map(Into::into).collect(); + } } From 61933fab0efd05675aaf6efa1bfdad49eaeb1451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 15:26:23 +0200 Subject: [PATCH 09/60] add test --- .../controller/searcher/component/builder.rs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 554ca16499f0..f483d4e3f3bb 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -361,8 +361,7 @@ mod tests { ], }, execution_context::ComponentGroup { - name: "Group with items not in DB and not in completions".into(), - name: "Group with items not in DB".into(), + name: "Group 2".into(), color: None, components: vec![ SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), @@ -372,9 +371,22 @@ mod tests { ], }, ]; - builder.set_favorites(&suggestion_db, groups); - builder.extend(&suggestion_db, &completion_ids); + builder.set_favorites(&suggestion_db, &groups); + builder.extend(&suggestion_db, completion_ids.into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); + let expected = vec![ + ComparableGroupData { + name: "Group 1", + component_id: None, + entries: vec![0, 0], + }, + ComparableGroupData { + name: "Group 2", + component_id: None, + entries: vec![], + }, + ]; + assert_eq!(favorites, expected); } } From d0780097f6c8c3a56284b0339fc3b968a1c6e285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 15:26:44 +0200 Subject: [PATCH 10/60] cargo fmt --- .../controller/searcher/component/builder.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index f483d4e3f3bb..dd04383f0c82 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -138,7 +138,8 @@ impl List { .filter_map(|g| component::Group::from_execution_context_component_group(g, db)) .collect(); for group in &*self.favorites { - // TODO[MC]: can we delete this code, due to only showing IDs of completions returned by Engine? + // TODO[MC]: can we delete this code, due to only showing IDs of completions returned by + // Engine? self.all_components.extend(group.entries.borrow().iter().cloned()); } } @@ -349,8 +350,8 @@ mod tests { const SUGGESTION_NAME_IN_COMPLETION_IDS: &str = "test.Test.TopModule1"; let groups = [ execution_context::ComponentGroup { - name: "Group 1".into(), - color: None, + name: "Group 1".into(), + color: None, components: vec![ SUGGESTION_NAME_IN_COMPLETION_IDS.into(), SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), @@ -361,8 +362,8 @@ mod tests { ], }, execution_context::ComponentGroup { - name: "Group 2".into(), - color: None, + name: "Group 2".into(), + color: None, components: vec![ SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), SUGGESTION_NAME_NOT_IN_DB.into(), @@ -377,14 +378,14 @@ mod tests { let favorites: Vec = list.favorites.iter().map(Into::into).collect(); let expected = vec![ ComparableGroupData { - name: "Group 1", + name: "Group 1", component_id: None, - entries: vec![0, 0], + entries: vec![0, 0], }, ComparableGroupData { - name: "Group 2", + name: "Group 2", component_id: None, - entries: vec![], + entries: vec![], }, ]; assert_eq!(favorites, expected); From 226f18a1f5b1cb5690c58a51f164b1043fef138a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 15:42:59 +0200 Subject: [PATCH 11/60] retain_components_by_id --- .../src/controller/searcher/component/builder.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index dd04383f0c82..b44a1346df35 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -67,7 +67,7 @@ impl ModuleGroups { pub struct List { all_components: Vec, // TODO[MC]: only keep component IDs at this stage? // TODO[MC]: use HashMap - component_ids: HashSet, + component_ids_to_retain: HashSet, module_groups: HashMap, local_scope: component::Group, favorites: component::group::List, @@ -101,7 +101,7 @@ impl List { let lookup_component_by_id = |id| Some(Component::new(id, db.lookup(id).ok()?)); let components = entries.into_iter().filter_map(lookup_component_by_id); for component in components { - self.component_ids.insert(*component.id); + self.component_ids_to_retain.insert(*component.id); let mut component_inserted_somewhere = false; if let Some(parent_module) = component.suggestion.parent_module() { if let Some(parent_group) = self.lookup_module_group(db, &parent_module) { @@ -171,7 +171,8 @@ impl List { /// Build the list, sorting all group lists and groups' contents appropriately. (Does not sort /// the [`component::List::favorites`].) - pub fn build(self) -> component::List { + pub fn build(mut self) -> component::List { + self.retain_components_by_id(); let components_order = component::Order::ByNameNonModulesThenModules; for group in self.module_groups.values() { group.content.update_sorting_and_visibility(components_order); @@ -185,7 +186,6 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); - self.retain_favorites(); component::List { all_components: Rc::new(self.all_components), top_modules: top_mdl_bld.build(), @@ -199,10 +199,12 @@ impl List { } } - fn retain_favorites(&self) { + fn retain_components_by_id(&mut self) { + let component_id_in_retain_set = |c: &Component| self.component_ids_to_retain.contains(&c.id); for group in &*self.favorites { - group.entries.borrow_mut().retain(|c| self.component_ids.contains(&c.id)); + group.entries.borrow_mut().retain(component_id_in_retain_set); } + self.all_components.retain(component_id_in_retain_set); } } From 760b54af9bc54c2f738335e043468023f665998a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 16:00:30 +0200 Subject: [PATCH 12/60] retain_favorites_with_ids_passed_to_extend --- .../controller/searcher/component/builder.rs | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index b44a1346df35..c160dce6fbcc 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -65,12 +65,13 @@ impl ModuleGroups { /// groups. #[derive(Clone, Debug, Default)] pub struct List { - all_components: Vec, // TODO[MC]: only keep component IDs at this stage? - // TODO[MC]: use HashMap - component_ids_to_retain: HashSet, - module_groups: HashMap, - local_scope: component::Group, - favorites: component::group::List, + all_components: Vec, + /// IDs passed as arguments to the [`extend`] method and found in + /// [`model::SuggestionDatabase`]. + ids_passed_to_extend: HashSet, + module_groups: HashMap, + local_scope: component::Group, + favorites: component::group::List, } impl List { @@ -101,7 +102,7 @@ impl List { let lookup_component_by_id = |id| Some(Component::new(id, db.lookup(id).ok()?)); let components = entries.into_iter().filter_map(lookup_component_by_id); for component in components { - self.component_ids_to_retain.insert(*component.id); + self.ids_passed_to_extend.insert(*component.id); let mut component_inserted_somewhere = false; if let Some(parent_module) = component.suggestion.parent_module() { if let Some(parent_group) = self.lookup_module_group(db, &parent_module) { @@ -172,7 +173,6 @@ impl List { /// Build the list, sorting all group lists and groups' contents appropriately. (Does not sort /// the [`component::List::favorites`].) pub fn build(mut self) -> component::List { - self.retain_components_by_id(); let components_order = component::Order::ByNameNonModulesThenModules; for group in self.module_groups.values() { group.content.update_sorting_and_visibility(components_order); @@ -186,6 +186,7 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); + self.retain_favorites_with_ids_passed_to_extend(); component::List { all_components: Rc::new(self.all_components), top_modules: top_mdl_bld.build(), @@ -199,12 +200,13 @@ impl List { } } - fn retain_components_by_id(&mut self) { - let component_id_in_retain_set = |c: &Component| self.component_ids_to_retain.contains(&c.id); + fn retain_favorites_with_ids_passed_to_extend(&mut self) { + let ids_passed_to_extend = &self.ids_passed_to_extend; + let component_id_passed_to_extend = |c: &Component| ids_passed_to_extend.contains(&c.id); for group in &*self.favorites { - group.entries.borrow_mut().retain(component_id_in_retain_set); + group.entries.borrow_mut().retain(component_id_passed_to_extend); } - self.all_components.retain(component_id_in_retain_set); + self.all_components.retain(component_id_passed_to_extend); } } From cc63b029a1df633fe788c2e9879a08fa6c04223a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 16:02:23 +0200 Subject: [PATCH 13/60] CLEANUP a comment --- app/gui/src/controller/searcher/component/builder.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index c160dce6fbcc..d797b6d549c4 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -139,8 +139,6 @@ impl List { .filter_map(|g| component::Group::from_execution_context_component_group(g, db)) .collect(); for group in &*self.favorites { - // TODO[MC]: can we delete this code, due to only showing IDs of completions returned by - // Engine? self.all_components.extend(group.entries.borrow().iter().cloned()); } } From 13fab9b4c977dbd3deb3fcc79bc62fff0db69713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 16:20:08 +0200 Subject: [PATCH 14/60] renames in test --- .../controller/searcher/component/builder.rs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index d797b6d549c4..c5b415adb8b5 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -344,38 +344,38 @@ mod tests { #[test] fn building_component_list_with_favorites() { let logger = Logger::new("tests::building_component_list_with_favorites"); - let suggestion_db = mock_suggestion_db(logger); + let db = mock_suggestion_db(logger); let mut builder = List::new(); - let completion_ids = [0, 1, 2]; - const SUGGESTION_NAME_NOT_IN_DB: &str = "test.Test.NameNotInSuggestionDb"; - const SUGGESTION_NAME_NOT_IN_COMPLETION_IDS: &str = "test.Test.TopModule1.fun1"; - const SUGGESTION_NAME_IN_COMPLETION_IDS: &str = "test.Test.TopModule1"; + let qn_of_db_entry_0 = db.lookup(0).unwrap().qualified_name(); + let qn_of_db_entry_3 = db.lookup(3).unwrap().qualified_name(); + const QN_NOT_IN_DB: &str = "test.Test.NameNotInSuggestionDb"; + assert_eq!(db.lookup_by_qualified_name_str(QN_NOT_IN_DB), None); let groups = [ execution_context::ComponentGroup { name: "Group 1".into(), color: None, components: vec![ - SUGGESTION_NAME_IN_COMPLETION_IDS.into(), - SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), - SUGGESTION_NAME_NOT_IN_DB.into(), - SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), - SUGGESTION_NAME_NOT_IN_DB.into(), - SUGGESTION_NAME_IN_COMPLETION_IDS.into(), + qn_of_db_entry_0.clone(), + qn_of_db_entry_3.clone(), + QN_NOT_IN_DB.into(), + qn_of_db_entry_3.clone(), + QN_NOT_IN_DB.into(), + qn_of_db_entry_0.clone(), ], }, execution_context::ComponentGroup { name: "Group 2".into(), color: None, components: vec![ - SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), - SUGGESTION_NAME_NOT_IN_DB.into(), - SUGGESTION_NAME_NOT_IN_COMPLETION_IDS.into(), - SUGGESTION_NAME_NOT_IN_DB.into(), + qn_of_db_entry_3.clone(), + QN_NOT_IN_DB.into(), + qn_of_db_entry_3.clone(), + QN_NOT_IN_DB.into(), ], }, ]; - builder.set_favorites(&suggestion_db, &groups); - builder.extend(&suggestion_db, completion_ids.into_iter()); + builder.set_favorites(&db, &groups); + builder.extend(&db, [0, 1, 2].into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); let expected = vec![ From 964c6540fb90ac2047c949be2b897c433ed4f28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 16:31:38 +0200 Subject: [PATCH 15/60] tweak comment --- app/gui/src/controller/searcher/component/builder.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index c5b415adb8b5..f456594fd1d4 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -168,8 +168,9 @@ impl List { } } - /// Build the list, sorting all group lists and groups' contents appropriately. (Does not sort - /// the [`component::List::favorites`].) + /// Build the list, sorting all group lists and groups' contents appropriately. Filter the + /// [`component::List::favorites`] (only components with IDs passed to [`extend`] are + /// retained), do not sort them. pub fn build(mut self) -> component::List { let components_order = component::Order::ByNameNonModulesThenModules; for group in self.module_groups.values() { From ab8f406b5922d435a80d8120862a169d238381fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 17:52:08 +0200 Subject: [PATCH 16/60] add test case in wasm test --- app/gui/src/controller/searcher.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index ba60420c8f90..8b75e4884fed 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1719,10 +1719,16 @@ pub mod test { name: "Test Group 1".to_string(), color: None, icon: None, - exports: vec![language_server::LibraryComponent { - name: module_qualified_name + ".testFunction1", - shortcut: None, - }], + exports: vec![ + language_server::LibraryComponent { + name: module_qualified_name.clone() + ".testFunction1", + shortcut: None, + }, + language_server::LibraryComponent { + name: module_qualified_name + ".testMethod1", + shortcut: None, + }, + ], }; // Create a test fixture with mocked Engine responses. let Fixture { mut test, searcher, entry1, entry9, .. } = From 998ad8b04381f359441ec5757c177fca6593cb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 7 Jul 2022 17:57:53 +0200 Subject: [PATCH 17/60] fix clippy --- app/gui/src/controller/searcher/component/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index f456594fd1d4..8024f5b0e799 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -361,7 +361,7 @@ mod tests { QN_NOT_IN_DB.into(), qn_of_db_entry_3.clone(), QN_NOT_IN_DB.into(), - qn_of_db_entry_0.clone(), + qn_of_db_entry_0, ], }, execution_context::ComponentGroup { @@ -370,7 +370,7 @@ mod tests { components: vec![ qn_of_db_entry_3.clone(), QN_NOT_IN_DB.into(), - qn_of_db_entry_3.clone(), + qn_of_db_entry_3, QN_NOT_IN_DB.into(), ], }, From e74d21128d1bd383e37d5f03764b09986edfb234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Mon, 11 Jul 2022 10:28:26 +0200 Subject: [PATCH 18/60] tweak comment --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 8024f5b0e799..974b0c2451f3 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -66,7 +66,7 @@ impl ModuleGroups { #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, - /// IDs passed as arguments to the [`extend`] method and found in + /// IDs passed as arguments to the [`extend`] method and present in /// [`model::SuggestionDatabase`]. ids_passed_to_extend: HashSet, module_groups: HashMap, From fcd8942e00df1c4bc5bb19669fa0c085b43862c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Mon, 11 Jul 2022 10:54:49 +0200 Subject: [PATCH 19/60] better test + docs --- app/gui/src/controller/searcher/component/builder.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 974b0c2451f3..b849236cf1ab 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -171,6 +171,10 @@ impl List { /// Build the list, sorting all group lists and groups' contents appropriately. Filter the /// [`component::List::favorites`] (only components with IDs passed to [`extend`] are /// retained), do not sort them. + /// + /// If a component group in favorites is empty after the filtering, the empty group is + /// retained. This allows layoing out the favorites in [Component + /// Browser](crate::controller::Searcher) in the same columns regardless of filtering. pub fn build(mut self) -> component::List { let components_order = component::Order::ByNameNonModulesThenModules; for group in self.module_groups.values() { @@ -342,12 +346,15 @@ mod tests { assert_eq!(local_scope_ids, expected_ids); } + /// Test building a component list with non-empty favorites. Verify that the favorites are + /// processed as described in the docs of the [`List::build`] method. #[test] fn building_component_list_with_favorites() { let logger = Logger::new("tests::building_component_list_with_favorites"); let db = mock_suggestion_db(logger); let mut builder = List::new(); let qn_of_db_entry_0 = db.lookup(0).unwrap().qualified_name(); + let qn_of_db_entry_1 = db.lookup(1).unwrap().qualified_name(); let qn_of_db_entry_3 = db.lookup(3).unwrap().qualified_name(); const QN_NOT_IN_DB: &str = "test.Test.NameNotInSuggestionDb"; assert_eq!(db.lookup_by_qualified_name_str(QN_NOT_IN_DB), None); @@ -361,6 +368,7 @@ mod tests { QN_NOT_IN_DB.into(), qn_of_db_entry_3.clone(), QN_NOT_IN_DB.into(), + qn_of_db_entry_1, qn_of_db_entry_0, ], }, @@ -383,7 +391,7 @@ mod tests { ComparableGroupData { name: "Group 1", component_id: None, - entries: vec![0, 0], + entries: vec![0, 1, 0], }, ComparableGroupData { name: "Group 2", From 9b60a90fb11de056f82440330a9b538b1ce2beea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 13 Jul 2022 16:58:15 +0200 Subject: [PATCH 20/60] DEBUG --- app/gui/src/controller/searcher.rs | 2 ++ app/gui/src/controller/searcher/component/group.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index e4a58969f1dc..ebbc00cb550d 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -964,6 +964,7 @@ impl Searcher { }); let responses: Result, _> = futures::future::join_all(requests).await.into_iter().collect(); + DEBUG!("MCDBG responses..."); match responses { Ok(responses) => { info!(this.logger, "Received suggestions from Language Server."); @@ -972,6 +973,7 @@ impl Searcher { data.actions = Actions::Loaded { list: Rc::new(list) }; let completions = responses.iter().flat_map(|r| r.results.iter().cloned()); data.components = this.make_component_list(completions); + DEBUG!("MCDBG data.components.favorites=" data.components.favorites;?); } Err(err) => { let msg = "Request for completions to the Language Server returned error"; diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index 2b33be0907a0..f972760a76dd 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -135,12 +135,14 @@ impl Group { fn restore_initial_order(&self) { let mut entries = self.entries.borrow_mut(); if entries.len() != self.initial_entries_order.len() { + DEBUG!("MCDBG why I don't see the error below?"); tracing::error!( "Tried to restore initial order in group where \ `initial_entries_order` is not initialized or up-to-date. Will keep the \ old order." ) } else { + DEBUG!("MCDBG clone initial entries @" self.initial_entries_order.len()); *entries = self.initial_entries_order.clone() } } From 8282b15a62ab9ecb3a61e54f7afb42c05dd29762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 13 Jul 2022 16:58:25 +0200 Subject: [PATCH 21/60] WIP set_initial_entries_order --- app/gui/src/controller/searcher/component/builder.rs | 9 ++++++++- app/gui/src/controller/searcher/component/group.rs | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 9f0abf606038..6798eecee4dd 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -206,9 +206,16 @@ impl List { fn retain_favorites_with_ids_passed_to_extend(&mut self) { let ids_passed_to_extend = &self.ids_passed_to_extend; let component_id_passed_to_extend = |c: &Component| ids_passed_to_extend.contains(&c.id); + // TODO: convert to functional style with `map` etc. + let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); for group in &*self.favorites { - group.entries.borrow_mut().retain(component_id_passed_to_extend); + let group2 = group.clone(); + group2.entries.borrow_mut().retain(component_id_passed_to_extend); + let group3 = group2.set_initial_entries_order(); + // *group = group.set_initial_entries_order(); + filtered_groups.push(group3); } + self.favorites = component::group::List::new(filtered_groups); self.all_components.retain(component_id_passed_to_extend); } } diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index f972760a76dd..d9c46faa759f 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -118,6 +118,13 @@ impl Group { }) } + pub fn set_initial_entries_order(self) -> Self { + let old_group_data = (*self.data).clone(); + let initial_entries_order = old_group_data.entries.borrow().clone(); + let group_data = Data { initial_entries_order, ..old_group_data }; + Group { data: Rc::new(group_data) } + } + /// Update the group sorting according to the `order` and update information about matched items /// count. pub fn update_sorting(&self, order: component::Order) { From 5961b134f07930d15289e4ffe67f87cad839f94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 13 Jul 2022 17:38:02 +0200 Subject: [PATCH 22/60] WIP matched_items --- app/gui/src/controller/searcher/component/builder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 6798eecee4dd..286e307e7054 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -211,6 +211,7 @@ impl List { for group in &*self.favorites { let group2 = group.clone(); group2.entries.borrow_mut().retain(component_id_passed_to_extend); + group2.matched_items.set(group2.entries.borrow().len()); let group3 = group2.set_initial_entries_order(); // *group = group.set_initial_entries_order(); filtered_groups.push(group3); From 5c0f2edac1848993ee1fed1786a16318c91d7e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 13 Jul 2022 17:47:03 +0200 Subject: [PATCH 23/60] Revert "DEBUG" This reverts commit e275f23f7097384233d27a9de1219bbd31e60d29. --- app/gui/src/controller/searcher.rs | 2 -- app/gui/src/controller/searcher/component/group.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index ebbc00cb550d..e4a58969f1dc 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -964,7 +964,6 @@ impl Searcher { }); let responses: Result, _> = futures::future::join_all(requests).await.into_iter().collect(); - DEBUG!("MCDBG responses..."); match responses { Ok(responses) => { info!(this.logger, "Received suggestions from Language Server."); @@ -973,7 +972,6 @@ impl Searcher { data.actions = Actions::Loaded { list: Rc::new(list) }; let completions = responses.iter().flat_map(|r| r.results.iter().cloned()); data.components = this.make_component_list(completions); - DEBUG!("MCDBG data.components.favorites=" data.components.favorites;?); } Err(err) => { let msg = "Request for completions to the Language Server returned error"; diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index d9c46faa759f..d8f92e912e2c 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -142,14 +142,12 @@ impl Group { fn restore_initial_order(&self) { let mut entries = self.entries.borrow_mut(); if entries.len() != self.initial_entries_order.len() { - DEBUG!("MCDBG why I don't see the error below?"); tracing::error!( "Tried to restore initial order in group where \ `initial_entries_order` is not initialized or up-to-date. Will keep the \ old order." ) } else { - DEBUG!("MCDBG clone initial entries @" self.initial_entries_order.len()); *entries = self.initial_entries_order.clone() } } From 70f9352524d7f0974a0d797df07dbd072302e081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 12:13:09 +0200 Subject: [PATCH 24/60] WIP with_initial_entries_order_filtered --- .../controller/searcher/component/builder.rs | 25 ++++++----- .../controller/searcher/component/group.rs | 41 ++++++++++++++++--- app/gui/src/lib.rs | 1 + 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 286e307e7054..59c7c17faa5e 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -206,17 +206,20 @@ impl List { fn retain_favorites_with_ids_passed_to_extend(&mut self) { let ids_passed_to_extend = &self.ids_passed_to_extend; let component_id_passed_to_extend = |c: &Component| ids_passed_to_extend.contains(&c.id); - // TODO: convert to functional style with `map` etc. - let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); - for group in &*self.favorites { - let group2 = group.clone(); - group2.entries.borrow_mut().retain(component_id_passed_to_extend); - group2.matched_items.set(group2.entries.borrow().len()); - let group3 = group2.set_initial_entries_order(); - // *group = group.set_initial_entries_order(); - filtered_groups.push(group3); - } - self.favorites = component::group::List::new(filtered_groups); + let filtered_fav_groups = std::mem::take(&mut self.favorites).into_iter().map(|g| g.with_initial_entries_order_filtered(component_id_passed_to_extend)).collect_vec(); + self.favorites = component::group::List::new(filtered_fav_groups); + + // // TODO: convert to functional style with `map` etc. + // let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); + // for group in &*self.favorites { + // let group2 = group.clone(); + // group2.entries.borrow_mut().retain(component_id_passed_to_extend); + // group2.matched_items.set(group2.entries.borrow().len()); + // let group3 = group2.set_initial_entries_order(); + // // *group = group.set_initial_entries_order(); + // filtered_groups.push(group3); + // } + // self.favorites = component::group::List::new(filtered_groups); self.all_components.retain(component_id_passed_to_extend); } } diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index d8f92e912e2c..a4ae2ff38624 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -118,13 +118,35 @@ impl Group { }) } - pub fn set_initial_entries_order(self) -> Self { - let old_group_data = (*self.data).clone(); - let initial_entries_order = old_group_data.entries.borrow().clone(); - let group_data = Data { initial_entries_order, ..old_group_data }; - Group { data: Rc::new(group_data) } + pub fn with_initial_entries_order_filtered(self, f: F) -> Self + where F: FnMut(&Component) -> bool + { + let mut group_data = Rc::unwrap_or_clone(self.data); + let mut initial_entries_order = std::mem::take(&mut group_data.initial_entries_order); + //&mut group_data.initial_entries_order; + initial_entries_order.retain(f); + let entries = RefCell::new(initial_entries_order.clone()); + let matched_items = Cell::new(initial_entries_order.len()); + let data = Rc::new(Data { + initial_entries_order, + entries, + matched_items, + ..group_data + }); + Group { data } + // let entries = data.entries.borrow().iter().filter(f).collect_vec(); + // entries.retain(f); + // // let initial_entries_order = original_data.initial_entries_order + // // let entries = } + // pub fn set_initial_entries_order(self) -> Self { + // let old_group_data = (*self.data).clone(); + // let initial_entries_order = old_group_data.entries.borrow().clone(); + // let group_data = Data { initial_entries_order, ..old_group_data }; + // Group { data: Rc::new(group_data) } + // } + /// Update the group sorting according to the `order` and update information about matched items /// count. pub fn update_sorting(&self, order: component::Order) { @@ -237,6 +259,15 @@ impl FromIterator for List { } } +impl IntoIterator for List { + type Item = Group; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + Rc::unwrap_or_clone(self.groups).into_iter() + } +} + impl Deref for List { type Target = [Group]; fn deref(&self) -> &Self::Target { diff --git a/app/gui/src/lib.rs b/app/gui/src/lib.rs index 948fb1162a43..4fc4e4b03111 100644 --- a/app/gui/src/lib.rs +++ b/app/gui/src/lib.rs @@ -29,6 +29,7 @@ #![recursion_limit = "512"] // === Features === +#![feature(arc_unwrap_or_clone)] #![feature(async_closure)] #![feature(associated_type_bounds)] #![feature(bool_to_option)] From c64022f5cd5d98424c430ef485e87f9c2168587f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 12:37:05 +0200 Subject: [PATCH 25/60] cleanup & fmt --- .../controller/searcher/component/builder.rs | 17 ++++--------- .../controller/searcher/component/group.rs | 24 +++---------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 59c7c17faa5e..cf34aab874fb 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -206,20 +206,11 @@ impl List { fn retain_favorites_with_ids_passed_to_extend(&mut self) { let ids_passed_to_extend = &self.ids_passed_to_extend; let component_id_passed_to_extend = |c: &Component| ids_passed_to_extend.contains(&c.id); - let filtered_fav_groups = std::mem::take(&mut self.favorites).into_iter().map(|g| g.with_initial_entries_order_filtered(component_id_passed_to_extend)).collect_vec(); + let filtered_fav_groups = std::mem::take(&mut self.favorites) + .into_iter() + .map(|g| g.with_initial_entries_order_filtered(component_id_passed_to_extend)) + .collect_vec(); self.favorites = component::group::List::new(filtered_fav_groups); - - // // TODO: convert to functional style with `map` etc. - // let mut filtered_groups = Vec::::with_capacity(self.favorites.len()); - // for group in &*self.favorites { - // let group2 = group.clone(); - // group2.entries.borrow_mut().retain(component_id_passed_to_extend); - // group2.matched_items.set(group2.entries.borrow().len()); - // let group3 = group2.set_initial_entries_order(); - // // *group = group.set_initial_entries_order(); - // filtered_groups.push(group3); - // } - // self.favorites = component::group::List::new(filtered_groups); self.all_components.retain(component_id_passed_to_extend); } } diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index a4ae2ff38624..0ff1595c9d05 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -118,35 +118,17 @@ impl Group { }) } - pub fn with_initial_entries_order_filtered(self, f: F) -> Self - where F: FnMut(&Component) -> bool - { + pub fn with_initial_entries_order_filtered(self, f: F) -> Self + where F: FnMut(&Component) -> bool { let mut group_data = Rc::unwrap_or_clone(self.data); let mut initial_entries_order = std::mem::take(&mut group_data.initial_entries_order); - //&mut group_data.initial_entries_order; initial_entries_order.retain(f); let entries = RefCell::new(initial_entries_order.clone()); let matched_items = Cell::new(initial_entries_order.len()); - let data = Rc::new(Data { - initial_entries_order, - entries, - matched_items, - ..group_data - }); + let data = Rc::new(Data { initial_entries_order, entries, matched_items, ..group_data }); Group { data } - // let entries = data.entries.borrow().iter().filter(f).collect_vec(); - // entries.retain(f); - // // let initial_entries_order = original_data.initial_entries_order - // // let entries = } - // pub fn set_initial_entries_order(self) -> Self { - // let old_group_data = (*self.data).clone(); - // let initial_entries_order = old_group_data.entries.borrow().clone(); - // let group_data = Data { initial_entries_order, ..old_group_data }; - // Group { data: Rc::new(group_data) } - // } - /// Update the group sorting according to the `order` and update information about matched items /// count. pub fn update_sorting(&self, order: component::Order) { From edddc81e6b1d553cfd2be511dcb46825a53da853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 14:04:43 +0200 Subject: [PATCH 26/60] rename with_... func --- app/gui/src/controller/searcher/component/builder.rs | 2 +- app/gui/src/controller/searcher/component/group.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index cf34aab874fb..7283453cb50b 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -208,7 +208,7 @@ impl List { let component_id_passed_to_extend = |c: &Component| ids_passed_to_extend.contains(&c.id); let filtered_fav_groups = std::mem::take(&mut self.favorites) .into_iter() - .map(|g| g.with_initial_entries_order_filtered(component_id_passed_to_extend)) + .map(|g| g.with_entries_in_initial_order_and_filtered(component_id_passed_to_extend)) .collect_vec(); self.favorites = component::group::List::new(filtered_fav_groups); self.all_components.retain(component_id_passed_to_extend); diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index 0ff1595c9d05..8e21492e5490 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -118,7 +118,7 @@ impl Group { }) } - pub fn with_initial_entries_order_filtered(self, f: F) -> Self + pub fn with_entries_in_initial_order_and_filtered(self, f: F) -> Self where F: FnMut(&Component) -> bool { let mut group_data = Rc::unwrap_or_clone(self.data); let mut initial_entries_order = std::mem::take(&mut group_data.initial_entries_order); From 2e28fd3b3560b11522e4b1c7e71abd2e3e499806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 14:16:58 +0200 Subject: [PATCH 27/60] WIP doc for with_... --- app/gui/src/controller/searcher/component/group.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index 8e21492e5490..df4c93140a7b 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -118,6 +118,14 @@ impl Group { }) } + /// Filter the [`Component`] entries stored in [`Group`] + /// Create a new [`Group`] containing only the [`Component`]s from `self` for which `f` returns + /// [`true`]. + /// Create a new [`Group`] with only those [`Component`]s in [`Group::initial_entries_order`] + /// retained for which `f` returns [`true`]. The [`Data + /// Create a new [`Group`] retaining only those [`Component`]s in the [`initial_entries_order`] + /// vector for which `f` returns [`true`]. The [`entries`] are set to a clone of + /// [`initial_entries_order`], and [`matched_items`] to the length of the vector. pub fn with_entries_in_initial_order_and_filtered(self, f: F) -> Self where F: FnMut(&Component) -> bool { let mut group_data = Rc::unwrap_or_clone(self.data); From bfedb83ce162ff0ffb224c67aff5be65058e5356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 14:18:41 +0200 Subject: [PATCH 28/60] doc for with_... --- app/gui/src/controller/searcher/component/group.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index df4c93140a7b..a81da8c22a5a 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -118,14 +118,9 @@ impl Group { }) } - /// Filter the [`Component`] entries stored in [`Group`] - /// Create a new [`Group`] containing only the [`Component`]s from `self` for which `f` returns - /// [`true`]. - /// Create a new [`Group`] with only those [`Component`]s in [`Group::initial_entries_order`] - /// retained for which `f` returns [`true`]. The [`Data /// Create a new [`Group`] retaining only those [`Component`]s in the [`initial_entries_order`] - /// vector for which `f` returns [`true`]. The [`entries`] are set to a clone of - /// [`initial_entries_order`], and [`matched_items`] to the length of the vector. + /// vector for which `f` returns [`true`]. The [`entries`] are set to a clone of the vector, + /// and [`matched_items`] are set to the length of the vector. pub fn with_entries_in_initial_order_and_filtered(self, f: F) -> Self where F: FnMut(&Component) -> bool { let mut group_data = Rc::unwrap_or_clone(self.data); From c59c6a9f34f8c386b50d70a51d39ec7f3c5cbdb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 15:25:59 +0200 Subject: [PATCH 29/60] review: improve docs --- .../src/controller/searcher/component/builder.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 7283453cb50b..95933cac5a52 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -63,11 +63,20 @@ impl ModuleGroups { /// /// The builder allow extending the list with new entries, and build a list with properly sorted /// groups. +/// +/// To build a [`component::List`] with non-empty [`component::List::favorites`], the following +/// methods should be called: +/// - [`set_favorites`] to specify order and grouping of [`Component`]s in favorites; +/// - [`extend`] to specify IDs of [`Component`]s which should be retained from the initial +/// [`component::Group`]s specified through [`set_favorites`] (allows filtering of favorites +/// e.g. by self type); +/// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed +/// to the methods listed above. #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, /// IDs passed as arguments to the [`extend`] method and present in - /// [`model::SuggestionDatabase`]. + /// [`model::SuggestionDatabase`]. Used to filter [`favorites`] in the [`build`] method. ids_passed_to_extend: HashSet, module_groups: HashMap, local_scope: component::Group, @@ -129,6 +138,8 @@ impl List { } /// Set the favorites in the list. Components are looked up by ID in the suggestion database. + /// When building a [`component::List`], only [`Component`]s with IDs passed to [`extend`] will + /// be retained (see the documentation of the [`build`] method). pub fn set_favorites<'a>( &mut self, db: &model::SuggestionDatabase, From fafff46320c9eeb550c0f92aeab92b4923941fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 15:28:15 +0200 Subject: [PATCH 30/60] tweak doc --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 95933cac5a52..19150816e857 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -76,7 +76,7 @@ impl ModuleGroups { pub struct List { all_components: Vec, /// IDs passed as arguments to the [`extend`] method and present in - /// [`model::SuggestionDatabase`]. Used to filter [`favorites`] in the [`build`] method. + /// [`model::SuggestionDatabase`]. Used by the [`build`] method to filter [`favorites`]. ids_passed_to_extend: HashSet, module_groups: HashMap, local_scope: component::Group, From 62ebf9b35f62cab49b4d7f35761b200d1511a057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 15:29:25 +0200 Subject: [PATCH 31/60] When building... --- app/gui/src/controller/searcher/component/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 19150816e857..86cb56b5f3a1 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -138,8 +138,8 @@ impl List { } /// Set the favorites in the list. Components are looked up by ID in the suggestion database. - /// When building a [`component::List`], only [`Component`]s with IDs passed to [`extend`] will - /// be retained (see the documentation of the [`build`] method). + /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to [`extend`] + /// will be retained (see the documentation of the [`build`] method). pub fn set_favorites<'a>( &mut self, db: &model::SuggestionDatabase, From d7299c32fa823d7f27a6efa38715d46cf8da4b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 15:30:11 +0200 Subject: [PATCH 32/60] fix layoing --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 86cb56b5f3a1..f299ae254a5f 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -184,7 +184,7 @@ impl List { /// retained), do not sort them. /// /// If a component group in favorites is empty after the filtering, the empty group is - /// retained. This allows layoing out the favorites in [Component + /// retained. This allows laying out the favorites in [Component /// Browser](crate::controller::Searcher) in the same columns regardless of filtering. pub fn build(mut self) -> component::List { let components_order = component::Order::ByNameNonModulesThenModules; From e2450bfd50224f653a6c75eb43ce820062011726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 15:30:59 +0200 Subject: [PATCH 33/60] link component group in docs --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index f299ae254a5f..1ca6347f9b34 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -183,7 +183,7 @@ impl List { /// [`component::List::favorites`] (only components with IDs passed to [`extend`] are /// retained), do not sort them. /// - /// If a component group in favorites is empty after the filtering, the empty group is + /// If a [`component::Group`] in favorites is empty after the filtering, the empty group is /// retained. This allows laying out the favorites in [Component /// Browser](crate::controller::Searcher) in the same columns regardless of filtering. pub fn build(mut self) -> component::List { From ea97bbbe443ac0e415aad28d0b3ae5d1f124248b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Thu, 14 Jul 2022 16:03:55 +0200 Subject: [PATCH 34/60] cargo fmt --- app/gui/src/controller/searcher/component/builder.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 1ca6347f9b34..de0a030975fe 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -68,10 +68,10 @@ impl ModuleGroups { /// methods should be called: /// - [`set_favorites`] to specify order and grouping of [`Component`]s in favorites; /// - [`extend`] to specify IDs of [`Component`]s which should be retained from the initial -/// [`component::Group`]s specified through [`set_favorites`] (allows filtering of favorites -/// e.g. by self type); -/// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed -/// to the methods listed above. +/// [`component::Group`]s specified through [`set_favorites`] (allows filtering of favorites e.g. +/// by self type); +/// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to +/// the methods listed above. #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, From 6e93a348cb8c084191cab946e24e7f05454e1d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 11:47:12 +0200 Subject: [PATCH 35/60] review: WIP set_favorites -> set_structure_of_favorites --- app/gui/src/controller/searcher.rs | 2 +- app/gui/src/controller/searcher/component.rs | 2 +- app/gui/src/controller/searcher/component/builder.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index e4a58969f1dc..063540c56e8c 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1187,7 +1187,7 @@ fn component_list_builder_with_favorites<'a>( if let Some((id, _)) = suggestion_db.lookup_by_qualified_name(local_scope_module) { builder = builder.with_local_scope_module_id(id); } - builder.set_favorites(suggestion_db, groups); + builder.set_structure_of_favorites(suggestion_db, groups); builder } diff --git a/app/gui/src/controller/searcher/component.rs b/app/gui/src/controller/searcher/component.rs index e5ffa87c61c3..d48da14f265f 100644 --- a/app/gui/src/controller/searcher/component.rs +++ b/app/gui/src/controller/searcher/component.rs @@ -400,7 +400,7 @@ pub(crate) mod tests { } let favorites = mock_favorites(&suggestion_db, &[3, 2]); let mut builder = builder::List::new().with_local_scope_module_id(0); - builder.set_favorites(&suggestion_db, &favorites); + builder.set_structure_of_favorites(&suggestion_db, &favorites); builder.extend(&suggestion_db, 0..4); let list = builder.build(); diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index de0a030975fe..708c19f4cc33 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -66,10 +66,10 @@ impl ModuleGroups { /// /// To build a [`component::List`] with non-empty [`component::List::favorites`], the following /// methods should be called: -/// - [`set_favorites`] to specify order and grouping of [`Component`]s in favorites; +/// - [`set_structure_of_favorites`] to specify order and grouping of [`Component`]s in favorites; /// - [`extend`] to specify IDs of [`Component`]s which should be retained from the initial -/// [`component::Group`]s specified through [`set_favorites`] (allows filtering of favorites e.g. -/// by self type); +/// [`component::Group`]s specified through [`set_structure_of_favorites`] (allows filtering of +/// favorites e.g. by self type); /// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to /// the methods listed above. #[derive(Clone, Debug, Default)] @@ -140,7 +140,7 @@ impl List { /// Set the favorites in the list. Components are looked up by ID in the suggestion database. /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to [`extend`] /// will be retained (see the documentation of the [`build`] method). - pub fn set_favorites<'a>( + pub fn set_structure_of_favorites<'a>( &mut self, db: &model::SuggestionDatabase, component_groups: impl IntoIterator, @@ -396,7 +396,7 @@ mod tests { ], }, ]; - builder.set_favorites(&db, &groups); + builder.set_structure_of_favorites(&db, &groups); builder.extend(&db, [0, 1, 2].into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); From 732b343cd07751f2b7a4c81a1c656f73a93bf756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 11:57:13 +0200 Subject: [PATCH 36/60] review: WIP rename extend to extend_list_and_enable_matching_favorites --- app/gui/src/controller/searcher.rs | 2 +- app/gui/src/controller/searcher/component.rs | 4 +-- .../controller/searcher/component/builder.rs | 31 ++++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 063540c56e8c..a160c8d2b704 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1043,7 +1043,7 @@ impl Searcher { entry_ids: impl IntoIterator, ) -> component::List { let mut builder = self.list_builder_with_favorites.deref().clone(); - builder.extend(&self.database, entry_ids); + builder.extend_list_and_enable_matching_favorites(&self.database, entry_ids); builder.build() } diff --git a/app/gui/src/controller/searcher/component.rs b/app/gui/src/controller/searcher/component.rs index d48da14f265f..3407100ce168 100644 --- a/app/gui/src/controller/searcher/component.rs +++ b/app/gui/src/controller/searcher/component.rs @@ -401,7 +401,7 @@ pub(crate) mod tests { let favorites = mock_favorites(&suggestion_db, &[3, 2]); let mut builder = builder::List::new().with_local_scope_module_id(0); builder.set_structure_of_favorites(&suggestion_db, &favorites); - builder.extend(&suggestion_db, 0..4); + builder.extend_list_and_enable_matching_favorites(&suggestion_db, 0..4); let list = builder.build(); list.update_filtering("fu"); @@ -446,7 +446,7 @@ pub(crate) mod tests { let logger = Logger::new("test::component_list_modules_tree"); let suggestion_db = mock_suggestion_db(logger); let mut builder = builder::List::new().with_local_scope_module_id(0); - builder.extend(&suggestion_db, 0..11); + builder.extend_list_and_enable_matching_favorites(&suggestion_db, 0..11); let list = builder.build(); // Verify that we can read all top-level modules from the component list. diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 708c19f4cc33..7d791c37144e 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -67,16 +67,17 @@ impl ModuleGroups { /// To build a [`component::List`] with non-empty [`component::List::favorites`], the following /// methods should be called: /// - [`set_structure_of_favorites`] to specify order and grouping of [`Component`]s in favorites; -/// - [`extend`] to specify IDs of [`Component`]s which should be retained from the initial -/// [`component::Group`]s specified through [`set_structure_of_favorites`] (allows filtering of -/// favorites e.g. by self type); +/// - [`extend_list_and_enable_matching_favorites`] to specify IDs of [`Component`]s which should +/// be retained from the initial [`component::Group`]s specified through +/// [`set_structure_of_favorites`] (allows filtering of favorites e.g. by self type); /// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to /// the methods listed above. #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, - /// IDs passed as arguments to the [`extend`] method and present in - /// [`model::SuggestionDatabase`]. Used by the [`build`] method to filter [`favorites`]. + /// IDs passed as arguments to the [`extend_list_and_enable_matching_favorites`] method and + /// present in [`model::SuggestionDatabase`]. Used by the [`build`] method to filter + /// [`favorites`]. ids_passed_to_extend: HashSet, module_groups: HashMap, local_scope: component::Group, @@ -90,9 +91,9 @@ impl List { } /// Return [`List`] with a new [`local_scope`] with its [`Group::component_id`] field set to - /// `module_id`. When the [`extend`] method is called on the returned object, components passed - /// to the method which have their parent module ID equal to `module_id` will be cloned into - /// [`component::List::local_scope`]. + /// `module_id`. When the [`extend_list_and_enable_matching_favorites`] method is called on the + /// returned object, components passed to the method which have their parent module ID equal + /// to `module_id` will be cloned into [`component::List::local_scope`]. pub fn with_local_scope_module_id(self, module_id: component::Id) -> Self { const LOCAL_SCOPE_GROUP_NAME: &str = "Local Scope"; let id = Some(module_id); @@ -101,7 +102,7 @@ impl List { } /// Extend the list with new entries looked up by ID in suggestion database. - pub fn extend( + pub fn extend_list_and_enable_matching_favorites( &mut self, db: &model::SuggestionDatabase, entries: impl IntoIterator, @@ -138,7 +139,8 @@ impl List { } /// Set the favorites in the list. Components are looked up by ID in the suggestion database. - /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to [`extend`] + /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to + /// [`extend_list_and_enable_matching_favorites`] /// will be retained (see the documentation of the [`build`] method). pub fn set_structure_of_favorites<'a>( &mut self, @@ -180,7 +182,8 @@ impl List { } /// Build the list, sorting all group lists and groups' contents appropriately. Filter the - /// [`component::List::favorites`] (only components with IDs passed to [`extend`] are + /// [`component::List::favorites`] (only components with IDs passed to + /// [`extend_list_and_enable_matching_favorites`] are /// retained), do not sort them. /// /// If a [`component::Group`] in favorites is empty after the filtering, the empty group is @@ -263,8 +266,8 @@ mod tests { let mut builder = List::new().with_local_scope_module_id(0); let first_part = (0..3).chain(6..11); let second_part = 3..6; - builder.extend(&suggestion_db, first_part); - builder.extend(&suggestion_db, second_part); + builder.extend_list_and_enable_matching_favorites(&suggestion_db, first_part); + builder.extend_list_and_enable_matching_favorites(&suggestion_db, second_part); let list = builder.build(); let top_modules: Vec = @@ -397,7 +400,7 @@ mod tests { }, ]; builder.set_structure_of_favorites(&db, &groups); - builder.extend(&db, [0, 1, 2].into_iter()); + builder.extend_list_and_enable_matching_favorites(&db, [0, 1, 2].into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); let expected = vec![ From a41e095c281cd3ecd469621c1de5183d60080b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:06:17 +0200 Subject: [PATCH 37/60] review: WIP favorites_structure, favorites_to_enable --- .../controller/searcher/component/builder.rs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 7d791c37144e..abcadc012380 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -74,14 +74,14 @@ impl ModuleGroups { /// the methods listed above. #[derive(Clone, Debug, Default)] pub struct List { - all_components: Vec, + all_components: Vec, /// IDs passed as arguments to the [`extend_list_and_enable_matching_favorites`] method and /// present in [`model::SuggestionDatabase`]. Used by the [`build`] method to filter - /// [`favorites`]. - ids_passed_to_extend: HashSet, - module_groups: HashMap, - local_scope: component::Group, - favorites: component::group::List, + /// [`favorites_structure`]. + favorites_to_enable: HashSet, + module_groups: HashMap, + local_scope: component::Group, + favorites_structure: component::group::List, } impl List { @@ -112,7 +112,7 @@ impl List { let lookup_component_by_id = |id| Some(Component::new(id, db.lookup(id).ok()?)); let components = entries.into_iter().filter_map(lookup_component_by_id); for component in components { - self.ids_passed_to_extend.insert(*component.id); + self.favorites_to_enable.insert(*component.id); let mut component_inserted_somewhere = false; if let Some(parent_module) = component.suggestion.parent_module() { if let Some(parent_group) = self.lookup_module_group(db, &parent_module) { @@ -147,11 +147,11 @@ impl List { db: &model::SuggestionDatabase, component_groups: impl IntoIterator, ) { - self.favorites = component_groups + self.favorites_structure = component_groups .into_iter() .filter_map(|g| component::Group::from_execution_context_component_group(g, db)) .collect(); - for group in &*self.favorites { + for group in &*self.favorites_structure { self.all_components.extend(group.entries.borrow().iter().cloned()); } } @@ -182,7 +182,7 @@ impl List { } /// Build the list, sorting all group lists and groups' contents appropriately. Filter the - /// [`component::List::favorites`] (only components with IDs passed to + /// [`component::List::favorites_structure`] (only components with IDs passed to /// [`extend_list_and_enable_matching_favorites`] are /// retained), do not sort them. /// @@ -203,7 +203,7 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); - self.retain_favorites_with_ids_passed_to_extend(); + self.retain_enabled_favorites(); component::List { all_components: Rc::new(self.all_components), top_modules: top_mdl_bld.build(), @@ -213,19 +213,19 @@ impl List { ), local_scope: self.local_scope, filtered: default(), - favorites: self.favorites, + favorites: self.favorites_structure, } } - fn retain_favorites_with_ids_passed_to_extend(&mut self) { - let ids_passed_to_extend = &self.ids_passed_to_extend; - let component_id_passed_to_extend = |c: &Component| ids_passed_to_extend.contains(&c.id); - let filtered_fav_groups = std::mem::take(&mut self.favorites) + fn retain_enabled_favorites(&mut self) { + let favorites_to_enable = &self.favorites_to_enable; + let id_in_favs_to_enable = |c: &Component| favorites_to_enable.contains(&c.id); + let filtered_fav_groups = std::mem::take(&mut self.favorites_structure) .into_iter() - .map(|g| g.with_entries_in_initial_order_and_filtered(component_id_passed_to_extend)) + .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_favs_to_enable)) .collect_vec(); - self.favorites = component::group::List::new(filtered_fav_groups); - self.all_components.retain(component_id_passed_to_extend); + self.favorites_structure = component::group::List::new(filtered_fav_groups); + self.all_components.retain(id_in_favs_to_enable); } } From ee5d332980a2f646cb9d711c36e231694336e47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:14:17 +0200 Subject: [PATCH 38/60] WIP add favs to all_components only when building --- app/gui/src/controller/searcher/component/builder.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index abcadc012380..9c35593faaac 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -151,9 +151,6 @@ impl List { .into_iter() .filter_map(|g| component::Group::from_execution_context_component_group(g, db)) .collect(); - for group in &*self.favorites_structure { - self.all_components.extend(group.entries.borrow().iter().cloned()); - } } fn lookup_module_group( @@ -225,7 +222,9 @@ impl List { .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_favs_to_enable)) .collect_vec(); self.favorites_structure = component::group::List::new(filtered_fav_groups); - self.all_components.retain(id_in_favs_to_enable); + for group in &*self.favorites_structure { + self.all_components.extend(group.entries.borrow().iter().cloned()); + } } } From 9130830aac1880b31a42d0b7323ecb3a5b94c177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:17:32 +0200 Subject: [PATCH 39/60] WIP build_favorites_and_add_to_all_components --- .../controller/searcher/component/builder.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 9c35593faaac..005a7d3e086b 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -200,31 +200,32 @@ impl List { top_mdl_bld.extend(top_modules_iter.clone().map(|g| g.content.clone_ref())); let mut top_mdl_flat_bld = component::group::AlphabeticalListBuilder::default(); top_mdl_flat_bld.extend(top_modules_iter.filter_map(|g| g.flattened_content.clone())); - self.retain_enabled_favorites(); + let favorites = self.build_favorites_and_add_to_all_components(); component::List { - all_components: Rc::new(self.all_components), - top_modules: top_mdl_bld.build(), + all_components: Rc::new(self.all_components), + top_modules: top_mdl_bld.build(), top_modules_flattened: top_mdl_flat_bld.build(), - module_groups: Rc::new( + module_groups: Rc::new( self.module_groups.into_iter().map(|(id, group)| (id, group.build())).collect(), ), - local_scope: self.local_scope, - filtered: default(), - favorites: self.favorites_structure, + local_scope: self.local_scope, + filtered: default(), + favorites, } } - fn retain_enabled_favorites(&mut self) { + fn build_favorites_and_add_to_all_components(&mut self) -> component::group::List { let favorites_to_enable = &self.favorites_to_enable; let id_in_favs_to_enable = |c: &Component| favorites_to_enable.contains(&c.id); let filtered_fav_groups = std::mem::take(&mut self.favorites_structure) .into_iter() .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_favs_to_enable)) .collect_vec(); - self.favorites_structure = component::group::List::new(filtered_fav_groups); - for group in &*self.favorites_structure { + let favorites = component::group::List::new(filtered_fav_groups); + for group in &*favorites { self.all_components.extend(group.entries.borrow().iter().cloned()); } + favorites } } From 02128600d67c12800956da1b2ee4f6e94013a329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:21:28 +0200 Subject: [PATCH 40/60] WIP further rename in build_favs... --- app/gui/src/controller/searcher/component/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 005a7d3e086b..efbebd68bdbf 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -217,11 +217,11 @@ impl List { fn build_favorites_and_add_to_all_components(&mut self) -> component::group::List { let favorites_to_enable = &self.favorites_to_enable; let id_in_favs_to_enable = |c: &Component| favorites_to_enable.contains(&c.id); - let filtered_fav_groups = std::mem::take(&mut self.favorites_structure) + let favorites_groups = std::mem::take(&mut self.favorites_structure) .into_iter() .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_favs_to_enable)) .collect_vec(); - let favorites = component::group::List::new(filtered_fav_groups); + let favorites = component::group::List::new(favorites_groups); for group in &*favorites { self.all_components.extend(group.entries.borrow().iter().cloned()); } From 4ae4fea5c078dd3a295bdc45a4f2ea0392de065e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:34:48 +0200 Subject: [PATCH 41/60] WIP rename set_grouping_and_order_of_favs --- app/gui/src/controller/searcher.rs | 2 +- app/gui/src/controller/searcher/component.rs | 2 +- app/gui/src/controller/searcher/component/builder.rs | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index a160c8d2b704..06d8d653b9f1 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1187,7 +1187,7 @@ fn component_list_builder_with_favorites<'a>( if let Some((id, _)) = suggestion_db.lookup_by_qualified_name(local_scope_module) { builder = builder.with_local_scope_module_id(id); } - builder.set_structure_of_favorites(suggestion_db, groups); + builder.set_grouping_and_order_of_favorites(suggestion_db, groups); builder } diff --git a/app/gui/src/controller/searcher/component.rs b/app/gui/src/controller/searcher/component.rs index 3407100ce168..83481570e809 100644 --- a/app/gui/src/controller/searcher/component.rs +++ b/app/gui/src/controller/searcher/component.rs @@ -400,7 +400,7 @@ pub(crate) mod tests { } let favorites = mock_favorites(&suggestion_db, &[3, 2]); let mut builder = builder::List::new().with_local_scope_module_id(0); - builder.set_structure_of_favorites(&suggestion_db, &favorites); + builder.set_grouping_and_order_of_favorites(&suggestion_db, &favorites); builder.extend_list_and_enable_matching_favorites(&suggestion_db, 0..4); let list = builder.build(); diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index efbebd68bdbf..5f0121fb63d4 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -66,10 +66,11 @@ impl ModuleGroups { /// /// To build a [`component::List`] with non-empty [`component::List::favorites`], the following /// methods should be called: -/// - [`set_structure_of_favorites`] to specify order and grouping of [`Component`]s in favorites; +/// - [`set_grouping_and_order_of_favorites`] to specify order and grouping of [`Component`]s in +/// favorites; /// - [`extend_list_and_enable_matching_favorites`] to specify IDs of [`Component`]s which should /// be retained from the initial [`component::Group`]s specified through -/// [`set_structure_of_favorites`] (allows filtering of favorites e.g. by self type); +/// [`set_grouping_and_order_of_favorites`] (allows filtering of favorites e.g. by self type); /// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to /// the methods listed above. #[derive(Clone, Debug, Default)] @@ -142,7 +143,7 @@ impl List { /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to /// [`extend_list_and_enable_matching_favorites`] /// will be retained (see the documentation of the [`build`] method). - pub fn set_structure_of_favorites<'a>( + pub fn set_grouping_and_order_of_favorites<'a>( &mut self, db: &model::SuggestionDatabase, component_groups: impl IntoIterator, @@ -399,7 +400,7 @@ mod tests { ], }, ]; - builder.set_structure_of_favorites(&db, &groups); + builder.set_grouping_and_order_of_favorites(&db, &groups); builder.extend_list_and_enable_matching_favorites(&db, [0, 1, 2].into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); From e21eb8954b988af5de15bde37e80fe400c65e31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:35:04 +0200 Subject: [PATCH 42/60] WIP start writing module doc --- app/gui/src/controller/searcher/component/builder.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 5f0121fb63d4..488b8bed874b 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -1,4 +1,11 @@ //! A module with entities used for building proper [`component::List`]. +//! +//! The [`List`] type builds a [`component::List`] with contents sorted as described below: +//! - [`component::Group`]s are sorted alphabetically by module name; +//! - [`Component`]s in each [`component::Group`] are ordered by non-modules sorted alphabetically +//! followed by modules sorted alphabetically; +//! - [`Component`]s and [`component::Group`]s in [`component::List::favorites`] keep the grouping +//! and order set with [`List::set_grouping_and_order_of_favorites`]. use crate::prelude::*; From 52233b102c5cc2b3924995bb2deefaf08f507efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:35:50 +0200 Subject: [PATCH 43/60] Groups...by name --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 488b8bed874b..0f204fe07b65 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -1,7 +1,7 @@ //! A module with entities used for building proper [`component::List`]. //! //! The [`List`] type builds a [`component::List`] with contents sorted as described below: -//! - [`component::Group`]s are sorted alphabetically by module name; +//! - [`component::Group`]s are sorted alphabetically by name; //! - [`Component`]s in each [`component::Group`] are ordered by non-modules sorted alphabetically //! followed by modules sorted alphabetically; //! - [`Component`]s and [`component::Group`]s in [`component::List::favorites`] keep the grouping From a0451f13f61ebe057474e015d6ff7b66db74c0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:36:41 +0200 Subject: [PATCH 44/60] Components in each Group are ordered... --- app/gui/src/controller/searcher/component/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 0f204fe07b65..0dcc1358eb04 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -2,7 +2,7 @@ //! //! The [`List`] type builds a [`component::List`] with contents sorted as described below: //! - [`component::Group`]s are sorted alphabetically by name; -//! - [`Component`]s in each [`component::Group`] are ordered by non-modules sorted alphabetically +//! - [`Component`]s in each [`component::Group`] are ordered: non-modules sorted alphabetically, //! followed by modules sorted alphabetically; //! - [`Component`]s and [`component::Group`]s in [`component::List::favorites`] keep the grouping //! and order set with [`List::set_grouping_and_order_of_favorites`]. From 72a75b5358f90500196a14ee19cd581e235adc1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:38:34 +0200 Subject: [PATCH 45/60] field grouping_and_order_of_favorites --- .../controller/searcher/component/builder.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 0dcc1358eb04..5063d5c6f43a 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -82,14 +82,14 @@ impl ModuleGroups { /// the methods listed above. #[derive(Clone, Debug, Default)] pub struct List { - all_components: Vec, + all_components: Vec, /// IDs passed as arguments to the [`extend_list_and_enable_matching_favorites`] method and /// present in [`model::SuggestionDatabase`]. Used by the [`build`] method to filter - /// [`favorites_structure`]. - favorites_to_enable: HashSet, - module_groups: HashMap, - local_scope: component::Group, - favorites_structure: component::group::List, + /// [`grouping_and_order_of_favorites`]. + favorites_to_enable: HashSet, + module_groups: HashMap, + local_scope: component::Group, + grouping_and_order_of_favorites: component::group::List, } impl List { @@ -155,7 +155,7 @@ impl List { db: &model::SuggestionDatabase, component_groups: impl IntoIterator, ) { - self.favorites_structure = component_groups + self.grouping_and_order_of_favorites = component_groups .into_iter() .filter_map(|g| component::Group::from_execution_context_component_group(g, db)) .collect(); @@ -187,7 +187,7 @@ impl List { } /// Build the list, sorting all group lists and groups' contents appropriately. Filter the - /// [`component::List::favorites_structure`] (only components with IDs passed to + /// [`component::List::grouping_and_order_of_favorites`] (only components with IDs passed to /// [`extend_list_and_enable_matching_favorites`] are /// retained), do not sort them. /// @@ -225,7 +225,7 @@ impl List { fn build_favorites_and_add_to_all_components(&mut self) -> component::group::List { let favorites_to_enable = &self.favorites_to_enable; let id_in_favs_to_enable = |c: &Component| favorites_to_enable.contains(&c.id); - let favorites_groups = std::mem::take(&mut self.favorites_structure) + let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) .into_iter() .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_favs_to_enable)) .collect_vec(); From 34daefc9e435acac85113826b0e6d9aa4bfd50cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:40:34 +0200 Subject: [PATCH 46/60] rename extend_list_and_enable_favs_with_ids --- app/gui/src/controller/searcher.rs | 2 +- app/gui/src/controller/searcher/component.rs | 4 ++-- .../controller/searcher/component/builder.rs | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 06d8d653b9f1..4423813d5196 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1043,7 +1043,7 @@ impl Searcher { entry_ids: impl IntoIterator, ) -> component::List { let mut builder = self.list_builder_with_favorites.deref().clone(); - builder.extend_list_and_enable_matching_favorites(&self.database, entry_ids); + builder.extend_list_and_enable_favorites_with_ids(&self.database, entry_ids); builder.build() } diff --git a/app/gui/src/controller/searcher/component.rs b/app/gui/src/controller/searcher/component.rs index 83481570e809..257bd75a2ad6 100644 --- a/app/gui/src/controller/searcher/component.rs +++ b/app/gui/src/controller/searcher/component.rs @@ -401,7 +401,7 @@ pub(crate) mod tests { let favorites = mock_favorites(&suggestion_db, &[3, 2]); let mut builder = builder::List::new().with_local_scope_module_id(0); builder.set_grouping_and_order_of_favorites(&suggestion_db, &favorites); - builder.extend_list_and_enable_matching_favorites(&suggestion_db, 0..4); + builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, 0..4); let list = builder.build(); list.update_filtering("fu"); @@ -446,7 +446,7 @@ pub(crate) mod tests { let logger = Logger::new("test::component_list_modules_tree"); let suggestion_db = mock_suggestion_db(logger); let mut builder = builder::List::new().with_local_scope_module_id(0); - builder.extend_list_and_enable_matching_favorites(&suggestion_db, 0..11); + builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, 0..11); let list = builder.build(); // Verify that we can read all top-level modules from the component list. diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 5063d5c6f43a..c721dc3bf65c 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -75,7 +75,7 @@ impl ModuleGroups { /// methods should be called: /// - [`set_grouping_and_order_of_favorites`] to specify order and grouping of [`Component`]s in /// favorites; -/// - [`extend_list_and_enable_matching_favorites`] to specify IDs of [`Component`]s which should +/// - [`extend_list_and_enable_favorites_with_ids`] to specify IDs of [`Component`]s which should /// be retained from the initial [`component::Group`]s specified through /// [`set_grouping_and_order_of_favorites`] (allows filtering of favorites e.g. by self type); /// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to @@ -83,7 +83,7 @@ impl ModuleGroups { #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, - /// IDs passed as arguments to the [`extend_list_and_enable_matching_favorites`] method and + /// IDs passed as arguments to the [`extend_list_and_enable_favorites_with_ids`] method and /// present in [`model::SuggestionDatabase`]. Used by the [`build`] method to filter /// [`grouping_and_order_of_favorites`]. favorites_to_enable: HashSet, @@ -99,7 +99,7 @@ impl List { } /// Return [`List`] with a new [`local_scope`] with its [`Group::component_id`] field set to - /// `module_id`. When the [`extend_list_and_enable_matching_favorites`] method is called on the + /// `module_id`. When the [`extend_list_and_enable_favorites_with_ids`] method is called on the /// returned object, components passed to the method which have their parent module ID equal /// to `module_id` will be cloned into [`component::List::local_scope`]. pub fn with_local_scope_module_id(self, module_id: component::Id) -> Self { @@ -110,7 +110,7 @@ impl List { } /// Extend the list with new entries looked up by ID in suggestion database. - pub fn extend_list_and_enable_matching_favorites( + pub fn extend_list_and_enable_favorites_with_ids( &mut self, db: &model::SuggestionDatabase, entries: impl IntoIterator, @@ -148,7 +148,7 @@ impl List { /// Set the favorites in the list. Components are looked up by ID in the suggestion database. /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to - /// [`extend_list_and_enable_matching_favorites`] + /// [`extend_list_and_enable_favorites_with_ids`] /// will be retained (see the documentation of the [`build`] method). pub fn set_grouping_and_order_of_favorites<'a>( &mut self, @@ -188,7 +188,7 @@ impl List { /// Build the list, sorting all group lists and groups' contents appropriately. Filter the /// [`component::List::grouping_and_order_of_favorites`] (only components with IDs passed to - /// [`extend_list_and_enable_matching_favorites`] are + /// [`extend_list_and_enable_favorites_with_ids`] are /// retained), do not sort them. /// /// If a [`component::Group`] in favorites is empty after the filtering, the empty group is @@ -274,8 +274,8 @@ mod tests { let mut builder = List::new().with_local_scope_module_id(0); let first_part = (0..3).chain(6..11); let second_part = 3..6; - builder.extend_list_and_enable_matching_favorites(&suggestion_db, first_part); - builder.extend_list_and_enable_matching_favorites(&suggestion_db, second_part); + builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, first_part); + builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, second_part); let list = builder.build(); let top_modules: Vec = @@ -408,7 +408,7 @@ mod tests { }, ]; builder.set_grouping_and_order_of_favorites(&db, &groups); - builder.extend_list_and_enable_matching_favorites(&db, [0, 1, 2].into_iter()); + builder.extend_list_and_enable_favorites_with_ids(&db, [0, 1, 2].into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); let expected = vec![ From 183825840233eba19db211d5062d64c0f79a4671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:50:00 +0200 Subject: [PATCH 47/60] WIP more module docs --- app/gui/src/controller/searcher/component/builder.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index c721dc3bf65c..7c6e03d976fc 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -1,11 +1,19 @@ //! A module with entities used for building proper [`component::List`]. //! //! The [`List`] type builds a [`component::List`] with contents sorted as described below: +//! //! - [`component::Group`]s are sorted alphabetically by name; //! - [`Component`]s in each [`component::Group`] are ordered: non-modules sorted alphabetically, //! followed by modules sorted alphabetically; //! - [`Component`]s and [`component::Group`]s in [`component::List::favorites`] keep the grouping //! and order set with [`List::set_grouping_and_order_of_favorites`]. +//! +//! When using the [`List`] type to build a [`component::List`], the components and groups are +//! sorted once and [`component::List::favorites`] will contain only [`Component`]s with IDs passed +//! to [`List::extend_list_and_enable_favorites_with_ids`]. +//! +//! +//! Using the [`List`] type instead of iteratively extending a [`component::List`] use crate::prelude::*; From 358113e1185b4c90cb00a8ac7b69e913a7349b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 12:50:13 +0200 Subject: [PATCH 48/60] WIP cleanup docs step 1 --- app/gui/src/controller/searcher/component/builder.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 7c6e03d976fc..f0437bae28e6 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -11,9 +11,6 @@ //! When using the [`List`] type to build a [`component::List`], the components and groups are //! sorted once and [`component::List::favorites`] will contain only [`Component`]s with IDs passed //! to [`List::extend_list_and_enable_favorites_with_ids`]. -//! -//! -//! Using the [`List`] type instead of iteratively extending a [`component::List`] use crate::prelude::*; From fa7e5d71e06d4654be4946bdb902f8d811afe839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 14:00:44 +0200 Subject: [PATCH 49/60] tweak doc to explain purpose of builder --- app/gui/src/controller/searcher/component/builder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index f0437bae28e6..835e3efad5cb 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -8,9 +8,11 @@ //! - [`Component`]s and [`component::Group`]s in [`component::List::favorites`] keep the grouping //! and order set with [`List::set_grouping_and_order_of_favorites`]. //! -//! When using the [`List`] type to build a [`component::List`], the components and groups are -//! sorted once and [`component::List::favorites`] will contain only [`Component`]s with IDs passed -//! to [`List::extend_list_and_enable_favorites_with_ids`]. +//! When using the [`List`] type to build a [`component::List`]: +//! - the components and groups are sorted once; +//! - [`component::List::favorites`] will contain only [`Component`]s with IDs that were passed +//! both to [`List::set_grouping_and_order_of_favorites`] and +//! [`List::extend_list_and_enable_favorites_with_ids`]. use crate::prelude::*; From a6e0de3a60ba6a50e14b57ebff571bc69d95b20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 14:05:32 +0200 Subject: [PATCH 50/60] move and doc favorites_to_enable --- app/gui/src/controller/searcher/component/builder.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 835e3efad5cb..5cd77aad72fd 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -90,13 +90,12 @@ impl ModuleGroups { #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, - /// IDs passed as arguments to the [`extend_list_and_enable_favorites_with_ids`] method and - /// present in [`model::SuggestionDatabase`]. Used by the [`build`] method to filter - /// [`grouping_and_order_of_favorites`]. - favorites_to_enable: HashSet, module_groups: HashMap, local_scope: component::Group, grouping_and_order_of_favorites: component::group::List, + /// IDs of [`Component`]s that should be added to [`component::List::favorites`] if they are + /// present in [`grouping_and_order_of_favorites`]. + favorites_to_enable: HashSet, } impl List { From 7379f7c1a6847ee1c8a3c9272d816957c1f8647c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 14:12:28 +0200 Subject: [PATCH 51/60] allowed_favorites --- .../src/controller/searcher/component/builder.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 5cd77aad72fd..3333be5ba34e 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -93,9 +93,9 @@ pub struct List { module_groups: HashMap, local_scope: component::Group, grouping_and_order_of_favorites: component::group::List, - /// IDs of [`Component`]s that should be added to [`component::List::favorites`] if they are - /// present in [`grouping_and_order_of_favorites`]. - favorites_to_enable: HashSet, + /// IDs of [`Component`]s allowed in [`component::List::favorites`] if they are also present in + /// [`grouping_and_order_of_favorites`]. + allowed_favorites: HashSet, } impl List { @@ -126,7 +126,7 @@ impl List { let lookup_component_by_id = |id| Some(Component::new(id, db.lookup(id).ok()?)); let components = entries.into_iter().filter_map(lookup_component_by_id); for component in components { - self.favorites_to_enable.insert(*component.id); + self.allowed_favorites.insert(*component.id); let mut component_inserted_somewhere = false; if let Some(parent_module) = component.suggestion.parent_module() { if let Some(parent_group) = self.lookup_module_group(db, &parent_module) { @@ -229,11 +229,11 @@ impl List { } fn build_favorites_and_add_to_all_components(&mut self) -> component::group::List { - let favorites_to_enable = &self.favorites_to_enable; - let id_in_favs_to_enable = |c: &Component| favorites_to_enable.contains(&c.id); + let allowed_favorites = &self.allowed_favorites; + let id_in_allowed_favs = |c: &Component| allowed_favorites.contains(&c.id); let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) .into_iter() - .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_favs_to_enable)) + .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_allowed_favs)) .collect_vec(); let favorites = component::group::List::new(favorites_groups); for group in &*favorites { From 2728721770e6f6095d9b74c22871fbe786143364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 14:13:41 +0200 Subject: [PATCH 52/60] extend_list_and_allow_... --- app/gui/src/controller/searcher.rs | 2 +- app/gui/src/controller/searcher/component.rs | 4 ++-- .../controller/searcher/component/builder.rs | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 4423813d5196..cf5ad3aeb41d 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1043,7 +1043,7 @@ impl Searcher { entry_ids: impl IntoIterator, ) -> component::List { let mut builder = self.list_builder_with_favorites.deref().clone(); - builder.extend_list_and_enable_favorites_with_ids(&self.database, entry_ids); + builder.extend_list_and_allow_favorites_with_ids(&self.database, entry_ids); builder.build() } diff --git a/app/gui/src/controller/searcher/component.rs b/app/gui/src/controller/searcher/component.rs index 257bd75a2ad6..d166e0dabd4d 100644 --- a/app/gui/src/controller/searcher/component.rs +++ b/app/gui/src/controller/searcher/component.rs @@ -401,7 +401,7 @@ pub(crate) mod tests { let favorites = mock_favorites(&suggestion_db, &[3, 2]); let mut builder = builder::List::new().with_local_scope_module_id(0); builder.set_grouping_and_order_of_favorites(&suggestion_db, &favorites); - builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, 0..4); + builder.extend_list_and_allow_favorites_with_ids(&suggestion_db, 0..4); let list = builder.build(); list.update_filtering("fu"); @@ -446,7 +446,7 @@ pub(crate) mod tests { let logger = Logger::new("test::component_list_modules_tree"); let suggestion_db = mock_suggestion_db(logger); let mut builder = builder::List::new().with_local_scope_module_id(0); - builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, 0..11); + builder.extend_list_and_allow_favorites_with_ids(&suggestion_db, 0..11); let list = builder.build(); // Verify that we can read all top-level modules from the component list. diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 3333be5ba34e..354e407a95a6 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -12,7 +12,7 @@ //! - the components and groups are sorted once; //! - [`component::List::favorites`] will contain only [`Component`]s with IDs that were passed //! both to [`List::set_grouping_and_order_of_favorites`] and -//! [`List::extend_list_and_enable_favorites_with_ids`]. +//! [`List::extend_list_and_allow_favorites_with_ids`]. use crate::prelude::*; @@ -82,7 +82,7 @@ impl ModuleGroups { /// methods should be called: /// - [`set_grouping_and_order_of_favorites`] to specify order and grouping of [`Component`]s in /// favorites; -/// - [`extend_list_and_enable_favorites_with_ids`] to specify IDs of [`Component`]s which should +/// - [`extend_list_and_allow_favorites_with_ids`] to specify IDs of [`Component`]s which should /// be retained from the initial [`component::Group`]s specified through /// [`set_grouping_and_order_of_favorites`] (allows filtering of favorites e.g. by self type); /// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to @@ -105,7 +105,7 @@ impl List { } /// Return [`List`] with a new [`local_scope`] with its [`Group::component_id`] field set to - /// `module_id`. When the [`extend_list_and_enable_favorites_with_ids`] method is called on the + /// `module_id`. When the [`extend_list_and_allow_favorites_with_ids`] method is called on the /// returned object, components passed to the method which have their parent module ID equal /// to `module_id` will be cloned into [`component::List::local_scope`]. pub fn with_local_scope_module_id(self, module_id: component::Id) -> Self { @@ -116,7 +116,7 @@ impl List { } /// Extend the list with new entries looked up by ID in suggestion database. - pub fn extend_list_and_enable_favorites_with_ids( + pub fn extend_list_and_allow_favorites_with_ids( &mut self, db: &model::SuggestionDatabase, entries: impl IntoIterator, @@ -154,7 +154,7 @@ impl List { /// Set the favorites in the list. Components are looked up by ID in the suggestion database. /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to - /// [`extend_list_and_enable_favorites_with_ids`] + /// [`extend_list_and_allow_favorites_with_ids`] /// will be retained (see the documentation of the [`build`] method). pub fn set_grouping_and_order_of_favorites<'a>( &mut self, @@ -194,7 +194,7 @@ impl List { /// Build the list, sorting all group lists and groups' contents appropriately. Filter the /// [`component::List::grouping_and_order_of_favorites`] (only components with IDs passed to - /// [`extend_list_and_enable_favorites_with_ids`] are + /// [`extend_list_and_allow_favorites_with_ids`] are /// retained), do not sort them. /// /// If a [`component::Group`] in favorites is empty after the filtering, the empty group is @@ -280,8 +280,8 @@ mod tests { let mut builder = List::new().with_local_scope_module_id(0); let first_part = (0..3).chain(6..11); let second_part = 3..6; - builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, first_part); - builder.extend_list_and_enable_favorites_with_ids(&suggestion_db, second_part); + builder.extend_list_and_allow_favorites_with_ids(&suggestion_db, first_part); + builder.extend_list_and_allow_favorites_with_ids(&suggestion_db, second_part); let list = builder.build(); let top_modules: Vec = @@ -414,7 +414,7 @@ mod tests { }, ]; builder.set_grouping_and_order_of_favorites(&db, &groups); - builder.extend_list_and_enable_favorites_with_ids(&db, [0, 1, 2].into_iter()); + builder.extend_list_and_allow_favorites_with_ids(&db, [0, 1, 2].into_iter()); let list = builder.build(); let favorites: Vec = list.favorites.iter().map(Into::into).collect(); let expected = vec![ From d5efc8afdc482991c88b160272cd35e129569f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 14:25:54 +0200 Subject: [PATCH 53/60] shorten List doc + update extend_... doc --- .../controller/searcher/component/builder.rs | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 354e407a95a6..ed9e0b47f5e1 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -8,9 +8,9 @@ //! - [`Component`]s and [`component::Group`]s in [`component::List::favorites`] keep the grouping //! and order set with [`List::set_grouping_and_order_of_favorites`]. //! -//! When using the [`List`] type to build a [`component::List`]: +//! When using the methods of the [`List`] type to build a [`component::List`]: //! - the components and groups are sorted once; -//! - [`component::List::favorites`] will contain only [`Component`]s with IDs that were passed +//! - [`component::List::favorites`] contains only [`Component`]s with IDs that were passed //! both to [`List::set_grouping_and_order_of_favorites`] and //! [`List::extend_list_and_allow_favorites_with_ids`]. @@ -73,20 +73,7 @@ impl ModuleGroups { // === List === // ============ -/// A [`component::List`] builder. -/// -/// The builder allow extending the list with new entries, and build a list with properly sorted -/// groups. -/// -/// To build a [`component::List`] with non-empty [`component::List::favorites`], the following -/// methods should be called: -/// - [`set_grouping_and_order_of_favorites`] to specify order and grouping of [`Component`]s in -/// favorites; -/// - [`extend_list_and_allow_favorites_with_ids`] to specify IDs of [`Component`]s which should -/// be retained from the initial [`component::Group`]s specified through -/// [`set_grouping_and_order_of_favorites`] (allows filtering of favorites e.g. by self type); -/// - [`build`] to get a [`component::group::List`] of favorites constrained by arguments passed to -/// the methods listed above. +/// A [`component::List`] builder. See the documentation of the module for more details. #[derive(Clone, Debug, Default)] pub struct List { all_components: Vec, @@ -115,7 +102,9 @@ impl List { Self { local_scope, ..self } } - /// Extend the list with new entries looked up by ID in suggestion database. + /// Extend the list with new entries looked up by ID in suggestion database. Allow those + /// entries to be present in [`component::List::favorites`] if also passed to the + /// [`set_grouping_and_order_of_favorites`] method. pub fn extend_list_and_allow_favorites_with_ids( &mut self, db: &model::SuggestionDatabase, From e16fc708de16c4653ead2e9bcc04a61e5aae81cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 14:39:46 +0200 Subject: [PATCH 54/60] shorten doc of build() and mention empty groups in module doc --- .../controller/searcher/component/builder.rs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index ed9e0b47f5e1..dc18c0e26c68 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -1,7 +1,6 @@ //! A module with entities used for building proper [`component::List`]. //! //! The [`List`] type builds a [`component::List`] with contents sorted as described below: -//! //! - [`component::Group`]s are sorted alphabetically by name; //! - [`Component`]s in each [`component::Group`] are ordered: non-modules sorted alphabetically, //! followed by modules sorted alphabetically; @@ -9,10 +8,14 @@ //! and order set with [`List::set_grouping_and_order_of_favorites`]. //! //! When using the methods of the [`List`] type to build a [`component::List`]: -//! - the components and groups are sorted once; -//! - [`component::List::favorites`] contains only [`Component`]s with IDs that were passed -//! both to [`List::set_grouping_and_order_of_favorites`] and +//! - The components and groups are sorted once. +//! - The [`component::List::favorites`] contain only components with IDs that were passed +//! both to [`List::set_grouping_and_order_of_favorites`] and to //! [`List::extend_list_and_allow_favorites_with_ids`]. +//! - Empty component groups are allowed in favorites. (This simplifies distributing groups of +//! favorites over columns in [Component Browser](crate::controller::Searcher) consistently. +//! That's because for the same input to [`List::set_grouping_and_order_of_favorites`], the same +//! number of groups will be always present in favorites.) use crate::prelude::*; @@ -141,10 +144,10 @@ impl List { } } - /// Set the favorites in the list. Components are looked up by ID in the suggestion database. - /// When [`build`]ing a [`component::List`], only [`Component`]s with IDs passed to - /// [`extend_list_and_allow_favorites_with_ids`] - /// will be retained (see the documentation of the [`build`] method). + /// Set the grouping and order of [`Components`] in [`component::List::favorites`]. A + /// [`Component`] with ID passed to the method will be added to favorites only if it is also + /// passed to [`extend_list_and_allow_favorites_with_ids`] and present in the suggestion + /// database. pub fn set_grouping_and_order_of_favorites<'a>( &mut self, db: &model::SuggestionDatabase, @@ -181,14 +184,7 @@ impl List { } } - /// Build the list, sorting all group lists and groups' contents appropriately. Filter the - /// [`component::List::grouping_and_order_of_favorites`] (only components with IDs passed to - /// [`extend_list_and_allow_favorites_with_ids`] are - /// retained), do not sort them. - /// - /// If a [`component::Group`] in favorites is empty after the filtering, the empty group is - /// retained. This allows laying out the favorites in [Component - /// Browser](crate::controller::Searcher) in the same columns regardless of filtering. + /// Build the list as described in the module's documentation. pub fn build(mut self) -> component::List { let components_order = component::Order::ByNameNonModulesThenModules; for group in self.module_groups.values() { From 3de3d8a58f3a45cd35d65903d7af0c81bb8cebc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 15:02:58 +0200 Subject: [PATCH 55/60] WIP retain_entries --- .../controller/searcher/component/builder.rs | 2 +- .../controller/searcher/component/group.rs | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index dc18c0e26c68..b8cb4f8d6739 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -218,7 +218,7 @@ impl List { let id_in_allowed_favs = |c: &Component| allowed_favorites.contains(&c.id); let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) .into_iter() - .map(|g| g.with_entries_in_initial_order_and_filtered(id_in_allowed_favs)) + .map(|mut g| { g.retain_entries(id_in_allowed_favs); g }) .collect_vec(); let favorites = component::group::List::new(favorites_groups); for group in &*favorites { diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index a81da8c22a5a..fe7cd60de81a 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -48,6 +48,12 @@ impl Data { matched_items: Cell::new(0), } } + + fn update_matched_items(&self) { + let entries = self.entries.borrow(); + let matched_items = entries.iter().take_while(|c| !c.is_filtered_out()).count(); + self.matched_items.set(matched_items); + } } @@ -118,18 +124,20 @@ impl Group { }) } - /// Create a new [`Group`] retaining only those [`Component`]s in the [`initial_entries_order`] - /// vector for which `f` returns [`true`]. The [`entries`] are set to a clone of the vector, - /// and [`matched_items`] are set to the length of the vector. - pub fn with_entries_in_initial_order_and_filtered(self, f: F) -> Self + /// Modify a [`Group`] keeping only the [`Component`]s for which `f` returns [`true`]. + pub fn retain_entries(&mut self, f: F) where F: FnMut(&Component) -> bool { let mut group_data = Rc::unwrap_or_clone(self.data); - let mut initial_entries_order = std::mem::take(&mut group_data.initial_entries_order); - initial_entries_order.retain(f); - let entries = RefCell::new(initial_entries_order.clone()); - let matched_items = Cell::new(initial_entries_order.len()); - let data = Rc::new(Data { initial_entries_order, entries, matched_items, ..group_data }); - Group { data } + group_data.entries.borrow_mut().retain(f); + group_data.initial_entries_order.retain(f); + group_data.update_matched_items(); + self.data = Rc::new(group_data); + // let mut initial_entries_order = std::mem::take(&mut group_data.initial_entries_order); + // initial_entries_order.retain(f); + // let entries = RefCell::new(initial_entries_order.clone()); + // let matched_items = Cell::new(initial_entries_order.len()); + // let data = Rc::new(Data { initial_entries_order, entries, matched_items, ..group_data }); + // Group { data } } /// Update the group sorting according to the `order` and update information about matched items @@ -141,9 +149,7 @@ impl Group { self.sort_by_name_non_modules_then_modules(), component::Order::ByMatch => self.sort_by_match(), } - let entries = self.entries.borrow(); - let matched_items = entries.iter().take_while(|c| !c.is_filtered_out()).count(); - self.matched_items.set(matched_items); + self.update_matched_items(); } fn restore_initial_order(&self) { From ddb1e7dffcb2585a27863379ba5ba0c3cb424580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 15:40:48 +0200 Subject: [PATCH 56/60] Group::retain_entries --- .../src/controller/searcher/component/group.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/gui/src/controller/searcher/component/group.rs b/app/gui/src/controller/searcher/component/group.rs index fe7cd60de81a..b49186609d00 100644 --- a/app/gui/src/controller/searcher/component/group.rs +++ b/app/gui/src/controller/searcher/component/group.rs @@ -124,20 +124,13 @@ impl Group { }) } - /// Modify a [`Group`] keeping only the [`Component`]s for which `f` returns [`true`]. - pub fn retain_entries(&mut self, f: F) + /// Modify the group keeping only the [`Component`]s for which `f` returns [`true`]. + pub fn retain_entries(&mut self, mut f: F) where F: FnMut(&Component) -> bool { - let mut group_data = Rc::unwrap_or_clone(self.data); - group_data.entries.borrow_mut().retain(f); + let group_data = Rc::make_mut(&mut self.data); + group_data.entries.borrow_mut().retain(&mut f); group_data.initial_entries_order.retain(f); group_data.update_matched_items(); - self.data = Rc::new(group_data); - // let mut initial_entries_order = std::mem::take(&mut group_data.initial_entries_order); - // initial_entries_order.retain(f); - // let entries = RefCell::new(initial_entries_order.clone()); - // let matched_items = Cell::new(initial_entries_order.len()); - // let data = Rc::new(Data { initial_entries_order, entries, matched_items, ..group_data }); - // Group { data } } /// Update the group sorting according to the `order` and update information about matched items From 7aceafa18d7565013e2b168b638a365e999d219c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 15:41:03 +0200 Subject: [PATCH 57/60] tweak method docs to not mention other methods --- app/gui/src/controller/searcher/component/builder.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index b8cb4f8d6739..08d539aa4567 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -106,8 +106,8 @@ impl List { } /// Extend the list with new entries looked up by ID in suggestion database. Allow those - /// entries to be present in [`component::List::favorites`] if also passed to the - /// [`set_grouping_and_order_of_favorites`] method. + /// entries to be present in [`component::List::favorites`]. See the module documentation for + /// more details. pub fn extend_list_and_allow_favorites_with_ids( &mut self, db: &model::SuggestionDatabase, @@ -144,10 +144,8 @@ impl List { } } - /// Set the grouping and order of [`Components`] in [`component::List::favorites`]. A - /// [`Component`] with ID passed to the method will be added to favorites only if it is also - /// passed to [`extend_list_and_allow_favorites_with_ids`] and present in the suggestion - /// database. + /// Set the grouping and order of [`Components`] in [`component::List::favorites`]. Skips + /// components not present in the suggestion database and skips empty groups. pub fn set_grouping_and_order_of_favorites<'a>( &mut self, db: &model::SuggestionDatabase, From 6c241ea47a245d007e79566280819b40fee32d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 15:46:23 +0200 Subject: [PATCH 58/60] cargo fmt --- app/gui/src/controller/searcher/component/builder.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 08d539aa4567..c19e457ac396 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -9,8 +9,8 @@ //! //! When using the methods of the [`List`] type to build a [`component::List`]: //! - The components and groups are sorted once. -//! - The [`component::List::favorites`] contain only components with IDs that were passed -//! both to [`List::set_grouping_and_order_of_favorites`] and to +//! - The [`component::List::favorites`] contain only components with IDs that were passed both to +//! [`List::set_grouping_and_order_of_favorites`] and to //! [`List::extend_list_and_allow_favorites_with_ids`]. //! - Empty component groups are allowed in favorites. (This simplifies distributing groups of //! favorites over columns in [Component Browser](crate::controller::Searcher) consistently. @@ -216,7 +216,10 @@ impl List { let id_in_allowed_favs = |c: &Component| allowed_favorites.contains(&c.id); let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) .into_iter() - .map(|mut g| { g.retain_entries(id_in_allowed_favs); g }) + .map(|mut g| { + g.retain_entries(id_in_allowed_favs); + g + }) .collect_vec(); let favorites = component::group::List::new(favorites_groups); for group in &*favorites { From d7495db6ba1e9266486c5bbaa21c12b25300274d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 16:09:27 +0200 Subject: [PATCH 59/60] WIP tweaking build_favorites... --- .../controller/searcher/component/builder.rs | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index c19e457ac396..634b20676041 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -212,20 +212,43 @@ impl List { } fn build_favorites_and_add_to_all_components(&mut self) -> component::group::List { + let grouping_and_order = std::mem::take(&mut self.grouping_and_order_of_favorites); + let mut favorites_groups = grouping_and_order.into_iter().collect_vec(); let allowed_favorites = &self.allowed_favorites; let id_in_allowed_favs = |c: &Component| allowed_favorites.contains(&c.id); - let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) - .into_iter() - .map(|mut g| { - g.retain_entries(id_in_allowed_favs); - g - }) - .collect_vec(); - let favorites = component::group::List::new(favorites_groups); - for group in &*favorites { + for group in favorites_groups.iter_mut() { + group.retain_entries(id_in_allowed_favs); self.all_components.extend(group.entries.borrow().iter().cloned()); } - favorites + component::group::List::new(favorites_groups) + +// let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites).into_iter().collect_vec(); + +// let retain_allowed_entries_in_group = |mut group| { +// g.retain_entries(id_in_allowed_favs); +// g +// }; +// let grouping_and_order = std::mem::take(&mut self.grouping_and_order_of_favorites); +// let favorites: component::Group::List = grouping_and_order +// .into_iter() +// .map(|mut g| +// // let group_retaining_entries_allowed_in_favs = |group| +// // let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) +// let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites).into_iter().collect_vec(); +// for g in favorites { +// g.retain_entries(id_in_allowed_favs); +// } +// // .into_iter() +// // .map(|mut g| { +// // g.retain_entries(id_in_allowed_favs); +// // g +// // }) +// // .collect_vec(); +// // let favorites = component::group::List::new(favorites_groups); +// for group in &*favorites { +// self.all_components.extend(group.entries.borrow().iter().cloned()); +// } +// favorites } } From 547be3bcf36c083f7bbe1cdd5247f70ea9ef7520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 20 Jul 2022 16:18:24 +0200 Subject: [PATCH 60/60] shorten & cleanup build_favorites_... --- .../controller/searcher/component/builder.rs | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index 634b20676041..fcb7c766017e 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -214,41 +214,11 @@ impl List { fn build_favorites_and_add_to_all_components(&mut self) -> component::group::List { let grouping_and_order = std::mem::take(&mut self.grouping_and_order_of_favorites); let mut favorites_groups = grouping_and_order.into_iter().collect_vec(); - let allowed_favorites = &self.allowed_favorites; - let id_in_allowed_favs = |c: &Component| allowed_favorites.contains(&c.id); for group in favorites_groups.iter_mut() { - group.retain_entries(id_in_allowed_favs); + group.retain_entries(|e| self.allowed_favorites.contains(&e.id)); self.all_components.extend(group.entries.borrow().iter().cloned()); } component::group::List::new(favorites_groups) - -// let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites).into_iter().collect_vec(); - -// let retain_allowed_entries_in_group = |mut group| { -// g.retain_entries(id_in_allowed_favs); -// g -// }; -// let grouping_and_order = std::mem::take(&mut self.grouping_and_order_of_favorites); -// let favorites: component::Group::List = grouping_and_order -// .into_iter() -// .map(|mut g| -// // let group_retaining_entries_allowed_in_favs = |group| -// // let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites) -// let favorites_groups = std::mem::take(&mut self.grouping_and_order_of_favorites).into_iter().collect_vec(); -// for g in favorites { -// g.retain_entries(id_in_allowed_favs); -// } -// // .into_iter() -// // .map(|mut g| { -// // g.retain_entries(id_in_allowed_favs); -// // g -// // }) -// // .collect_vec(); -// // let favorites = component::group::List::new(favorites_groups); -// for group in &*favorites { -// self.all_components.extend(group.entries.borrow().iter().cloned()); -// } -// favorites } }