From 5d6f902383ac27c9e762ee1b79d99ac309ac5f77 Mon Sep 17 00:00:00 2001 From: Adam Obuchowicz Date: Wed, 9 Aug 2023 13:07:13 +0200 Subject: [PATCH] Hide private entries in Component Browser (#7497) As in description. Fixes #7464 --- app/gui/src/controller/searcher.rs | 2 +- .../controller/searcher/component/builder.rs | 21 ++++++++++++++++++- app/gui/suggestion-database/src/mock.rs | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index b6d18dfff56f..e3999fda874c 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1229,7 +1229,7 @@ pub mod test { searcher.reload_list(); fixture.test.run_until_stalled(); // There are two virtual entries and two top-modules. - assert_eq!(dbg!(searcher.components().displayed()).len(), 4); + assert_eq!(searcher.components().displayed().len(), 4); let mut subscriber = searcher.subscribe(); searcher.enter_entry(3).expect("Entering entry failed"); diff --git a/app/gui/src/controller/searcher/component/builder.rs b/app/gui/src/controller/searcher/component/builder.rs index a662e48e75ae..ed9399c92543 100644 --- a/app/gui/src/controller/searcher/component/builder.rs +++ b/app/gui/src/controller/searcher/component/builder.rs @@ -13,6 +13,8 @@ use crate::model::suggestion_database; use double_representation::name::project::STANDARD_NAMESPACE; use double_representation::name::QualifiedName; use double_representation::name::QualifiedNameRef; +use enso_doc_parser::DocSection; +use enso_doc_parser::Tag; use enso_suggestion_database::SuggestionDatabase; @@ -238,6 +240,17 @@ impl WhenDisplayed { // Currently, the engine does the filtering. Self::Always } + + fn consider_tags(self, entry: &suggestion_database::Entry) -> Self { + let is_private_tag = + |doc: &DocSection| matches!(doc, DocSection::Tag { tag: Tag::Private, .. }); + let is_private = entry.documentation.iter().any(is_private_tag); + if is_private { + Self::Never + } else { + self + } + } } impl<'a> Builder<'a> { @@ -272,6 +285,7 @@ impl<'a> Builder<'a> { None if self.this_type.is_some() => WhenDisplayed::with_self_type(), None => WhenDisplayed::in_base_mode(&entry, group_id.is_some()), }; + let when_displayed = when_displayed.consider_tags(&entry); let component = Component::new_from_database_entry(id, entry, group_id); if matches!(when_displayed, WhenDisplayed::Always) { self.built_list.displayed_by_default.push(component.clone()); @@ -338,6 +352,7 @@ mod tests { use crate::controller::searcher::component::tests::check_groups; use double_representation::name::project; + use enso_suggestion_database::doc_section; use enso_suggestion_database::mock_suggestion_database; use ide_view::component_browser::component_list_panel::icon; @@ -348,6 +363,9 @@ mod tests { #[in_group("First Group")] fn fun2() -> Standard.Base.Any; + #[with_doc_section(doc_section!(@ Private, ""))] + fn private() -> Standard.Base.Any; + mod SubModule1 { fn fun4() -> Standard.Base.Any; } @@ -422,7 +440,8 @@ mod tests { "test.Test.TopModule1", "test.Test.TopModule2", ]); - assert_eq!(list.components.len(), database.keys().len()); + // We subtract a single private component. + assert_eq!(list.components.len(), database.keys().len() - 1); assert_eq!(list.groups.len(), 2); check_groups(&list, vec![Some(0), Some(0), Some(0), Some(1), None, None]); diff --git a/app/gui/suggestion-database/src/mock.rs b/app/gui/suggestion-database/src/mock.rs index eded8d6073c6..ad471c1303e6 100644 --- a/app/gui/suggestion-database/src/mock.rs +++ b/app/gui/suggestion-database/src/mock.rs @@ -351,6 +351,8 @@ macro_rules! mock_suggestion_database_entries { /// Each statement may be preceded by one or more attributes looking like in Rust. The attribute /// content is just a call to the [`Entry`] modifier - a method of [`Entry`] taking and returning /// modified `self`. +/// +/// See also [`doc_section!`] macro for defining documentation sections for entries. #[macro_export] macro_rules! mock_suggestion_database { ($($(#[$($attr_setter:tt)*])* $ns:ident.$project:ident { $($content:tt)* })*) => {