Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude components with a "PRIVATE" tag from the component browser #4085

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
65a8e1a
WIP: Filter PRIVATE entries in component browser
galin-enso Jan 25, 2023
80a5968
Filter private components when populating list
galin-enso Jan 26, 2023
b491748
Formatting
galin-enso Jan 26, 2023
3861004
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Jan 26, 2023
377f640
Add test
galin-enso Jan 26, 2023
f78fe9c
Formatting
galin-enso Jan 26, 2023
2cd7893
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Jan 26, 2023
b6ab078
Cleanup
galin-enso Jan 26, 2023
67f8714
Add changelog entry
galin-enso Jan 26, 2023
022c6b3
Make is_private a method of Component
galin-enso Jan 27, 2023
9e590d0
WIP filter out private components in iterator
galin-enso Jan 27, 2023
4708372
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Jan 30, 2023
40e8915
Make expected test results more readable
galin-enso Jan 30, 2023
6c2a10f
Improve changelog entry
galin-enso Jan 30, 2023
d40afdf
Clean up component entries lookup
galin-enso Jan 30, 2023
900d774
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Jan 31, 2023
591f997
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Jan 31, 2023
c14e5dc
Clean up literal definitions
galin-enso Jan 31, 2023
d2d0dc2
Merge branch 'wip/galin-enso/exclude-private-methods-from-cb-18421536…
galin-enso Jan 31, 2023
305a2aa
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 1, 2023
56077da
Remove accidentally commited binary file
galin-enso Feb 2, 2023
c99c198
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 2, 2023
6590917
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 6, 2023
a5007c7
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 8, 2023
e28ccc7
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 8, 2023
53a8f1d
Do not hide module/project-local private methods
galin-enso Feb 9, 2023
49e8e96
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 9, 2023
e5d87bf
Cleanup
galin-enso Feb 9, 2023
eaf0967
Fix test
galin-enso Feb 9, 2023
7e8df14
Merge branch 'develop' into wip/galin-enso/exclude-private-methods-fr…
galin-enso Feb 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -86,6 +86,8 @@
present only when the argument is of type that has a predefined set of values.
- [Separate component browser navigator sections for modules imported from
different namespaces][4044]
- [Internal components (private API) are not displayed in the component
browser.][4085]

#### EnsoGL (rendering engine)

Expand Down Expand Up @@ -461,6 +463,7 @@
[4052]: https://github.com/enso-org/enso/pull/4052
[4063]: https://github.com/enso-org/enso/pull/4063
[4078]: https://github.com/enso-org/enso/pull/4078
[4085]: https://github.com/enso-org/enso/pull/4085
[4097]: https://github.com/enso-org/enso/pull/4097

#### Enso Compiler
Expand Down
3 changes: 3 additions & 0 deletions app/gui/language/ast/impl/src/lib.rs
Expand Up @@ -85,6 +85,9 @@ pub mod constants {
/// The "void" atom returned by function meant to not return any argument.
pub const NOTHING: &str = "Nothing";
}

/// The tag name of documentation sections marked as "PRIVATE"
pub const PRIVATE_DOC_SECTION_TAG_NAME: &str = "PRIVATE";
}

pub use crumbs::Crumb;
Expand Down
13 changes: 13 additions & 0 deletions app/gui/src/controller/searcher/component.rs
Expand Up @@ -9,6 +9,7 @@ use crate::model::suggestion_database;
use convert_case::Case;
use convert_case::Casing;
use double_representation::name::QualifiedName;
use engine_protocol::language_server::DocSection;


// ==============
Expand Down Expand Up @@ -162,6 +163,18 @@ impl Component {
None => MatchInfo::DoesNotMatch,
};
}

/// Check whether the component contains the "PRIVATE" tag.
pub fn is_private(&self) -> bool {
match &self.data {
Data::FromDatabase { entry, .. } => entry.documentation.iter().any(|doc| match doc {
DocSection::Tag { name, .. } =>
name == ast::constants::PRIVATE_DOC_SECTION_TAG_NAME,
_ => false,
}),
_ => false,
}
}
}

impl From<Rc<hardcoded::Snippet>> for Component {
Expand Down
57 changes: 53 additions & 4 deletions app/gui/src/controller/searcher/component/builder.rs
Expand Up @@ -152,6 +152,24 @@ pub struct List {
allowed_favorites: HashSet<component::Id>,
}

struct ComponentWithDbEntry {
component: Component,
entry: Rc<suggestion_database::Entry>,
id: usize,
}

impl ComponentWithDbEntry {
fn new(db: &model::SuggestionDatabase, id: usize) -> Option<ComponentWithDbEntry> {
let entry = db.lookup(id).ok()?;
let component = Component::new_from_database_entry(id, entry.clone_ref());
if component.is_private() {
None
} else {
Some(ComponentWithDbEntry { component, entry, id })
}
}
}

impl List {
/// Construct List builder without content.
pub fn new() -> Self {
Expand Down Expand Up @@ -180,11 +198,9 @@ impl List {
) {
use suggestion_database::entry::Kind;
let local_scope_id = self.local_scope.component_id;
let id_and_looked_up_entry = |id| Some((id, db.lookup(id).ok()?));
let ids_and_entries = entry_ids.into_iter().filter_map(id_and_looked_up_entry);
for (id, entry) in ids_and_entries {
let components = entry_ids.into_iter().filter_map(|id| ComponentWithDbEntry::new(db, id));
for ComponentWithDbEntry { component, entry, id } in components {
self.allowed_favorites.insert(id);
let component = Component::new_from_database_entry(id, entry.clone_ref());
let mut component_inserted_somewhere = false;
if let Some(parent_module) = entry.parent_module() {
if let Some(parent_group) = self.lookup_module_group(db, parent_module.clone_ref())
Expand Down Expand Up @@ -593,4 +609,37 @@ mod tests {
assert_eq!(group_at_1.name, "Group 1");
check_names_and_order_of_group_entries(group_at_1, &[qn_of_db_entry_1.name()]);
}

/// Test building a component list with a private component. The private component will be
/// excluded from the list.
#[test]
fn building_component_list_with_private_component() {
use ast::constants::PRIVATE_DOC_SECTION_TAG_NAME as PRIVATE_TAG;
let private_doc_section = enso_suggestion_database::doc_section!(@ PRIVATE_TAG, "");
let suggestion_db = enso_suggestion_database::mock_suggestion_database! {
test.Test {
mod TopModule {
fn fun1() -> Standard.Base.Any;
#[with_doc_section(private_doc_section)]
fn private_fun2() -> Standard.Base.Any;
fn fun3() -> Standard.Base.Any;
}
}
};
let mut builder = List::new().with_local_scope_module_id(1);
// ID's for `test.Test`, `TopModule` and 3 function ID's in `suggestion_db`.
let entry_ids = 0..5;
galin-enso marked this conversation as resolved.
Show resolved Hide resolved
builder.extend_list_and_allow_favorites_with_ids(&suggestion_db, entry_ids);
let list = builder.build();
let component_names: Vec<_> = list
.all_components
.iter()
.filter_map(|component| match &component.data {
component::Data::FromDatabase { entry, .. } => Some(&entry.name),
_ => None,
})
.collect();
let expected = vec!["TopModule", "fun1", "fun3"];
assert_eq!(component_names, expected);
}
}
Binary file added sunmscapi.dll
Binary file not shown.