Skip to content

Commit

Permalink
Hide private entries in Component Browser (#7497)
Browse files Browse the repository at this point in the history
As in description.

Fixes #7464
  • Loading branch information
farmaazon authored Aug 9, 2023
1 parent 0e20644 commit 5d6f902
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/gui/src/controller/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
21 changes: 20 additions & 1 deletion app/gui/src/controller/searcher/component/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 2 additions & 0 deletions app/gui/suggestion-database/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)* })*) => {
Expand Down

0 comments on commit 5d6f902

Please sign in to comment.