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

Component list panel integration #3530

Merged
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3b20835
Component Browser visible on the scene.
farmaazon Jun 7, 2022
508fa95
Add a new selection box to the component list panel view
vitvakatu Jun 17, 2022
66ec869
Fix layers
farmaazon Jun 23, 2022
254df3c
Fix memory in searcher-list-panel integration with component-group se…
MichaelMauderer Jun 30, 2022
4a42bae
Fixes after rebase
farmaazon Jul 1, 2022
22570f6
Avoid patching the file `msdfgen_wasm.js` more than once.
MichaelMauderer Jul 3, 2022
2146525
A workaround for layers problem
farmaazon Jul 4, 2022
84e58b8
Fixes after rebase
farmaazon Jul 4, 2022
5196f49
Clean up - linter and changelog
farmaazon Jul 4, 2022
14f4da7
Merge remote-tracking branch 'origin/develop' into wip/farmaazon/comp…
farmaazon Jul 5, 2022
307b1f4
Local scope integration
farmaazon Jun 29, 2022
42e093b
Refactored styles a bit
farmaazon Jul 5, 2022
b2ca23e
Fix Favorites ordering
farmaazon Jul 6, 2022
03cf924
Fix option parsing and remove logs
farmaazon Jul 6, 2022
336640b
Merge remote-tracking branch 'origin/develop' into wip/farmaazon/comp…
farmaazon Jul 6, 2022
c3853e8
Self-review
farmaazon Jul 6, 2022
b38b7f6
Fix formatting
farmaazon Jul 6, 2022
64364ba
Bump size limit
farmaazon Jul 7, 2022
ffb0228
Merge remote-tracking branch 'origin/develop' into wip/farmaazon/comp…
farmaazon Jul 7, 2022
954739f
Apply @wdanilo review
farmaazon Jul 7, 2022
e3a8a46
Merge remote-tracking branch 'origin/develop' into wip/farmaazon/comp…
farmaazon Jul 7, 2022
7de4724
Fixes
farmaazon Jul 7, 2022
df44c8b
Fix compilation. What a shame!
farmaazon Jul 8, 2022
8ff7591
Merge remote-tracking branch 'origin/develop' into wip/farmaazon/comp…
farmaazon Jul 8, 2022
b5b760c
Merge remote-tracking branch 'origin/develop' into wip/farmaazon/comp…
farmaazon Jul 11, 2022
e6b138c
Some QA fixes
farmaazon Jul 11, 2022
b8e75ef
Next QA fixe
farmaazon Jul 11, 2022
30cecc2
Merge branch 'develop' into wip/farmaazon/component-list-panel-integr…
farmaazon Jul 13, 2022
ee7a4af
Apply formatter
farmaazon Jul 13, 2022
4f5d013
Merge branch 'develop' into wip/farmaazon/component-list-panel-integr…
mergify[bot] Jul 13, 2022
4ac9652
Fix tests
farmaazon Jul 13, 2022
b4fc89a
Merge branch 'develop' into wip/farmaazon/component-list-panel-integr…
mergify[bot] Jul 13, 2022
36182e0
Merge branch 'develop' into wip/farmaazon/component-list-panel-integr…
mergify[bot] Jul 13, 2022
7b12fe2
Bump size limit
farmaazon Jul 14, 2022
785621d
Merge branch 'develop' into wip/farmaazon/component-list-panel-integr…
mergify[bot] Jul 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ Cargo.lock
# TODO [mwu]: Adjust Engine build to not leave them.
ci-build/
enso/

# Popular IDEs
.idea
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
node cration.][3186]
- [Fixed developer console error about failing to decode a notification
"executionContext/visualisationEvaluationFailed"][3193]
- [New Version of the Node Searcher - the Component Browser][3530] The available
methods, atoms and functions are presented in nice, categorized view. The most
popular tools are available at hand. The The panel is unstable, and thus is
available under the `--enable-new-component-browser` flag.

#### EnsoGL (rendering engine)

Expand Down Expand Up @@ -235,6 +239,7 @@
[3519]: https://github.com/enso-org/enso/pull/3519
[3523]: https://github.com/enso-org/enso/pull/3523
[3528]: https://github.com/enso-org/enso/pull/3528
[3530]: https://github.com/enso-org/enso/pull/3530
[3542]: https://github.com/enso-org/enso/pull/3542
[3551]: https://github.com/enso-org/enso/pull/3551
[3552]: https://github.com/enso-org/enso/pull/3552
Expand Down
62 changes: 38 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ ensogl-drop-manager = { path = "../../lib/rust/ensogl/component/drop-manager" }
fuzzly = { path = "../../lib/rust/fuzzly" }
ast = { path = "language/ast/impl" }
ide-view = { path = "view" }
ide-view-component-group = { path = "view/component-browser/component-group" }
engine-protocol = { path = "controller/engine-protocol" }
json-rpc = { path = "../../lib/rust/json-rpc" }
parser = { path = "language/parser" }
span-tree = { path = "language/span-tree" }
bimap = { version = "0.4.0" }
console_error_panic_hook = { version = "0.1.6" }
convert_case = { version = "0.5.0" }
failure = { version = "0.1.6" }
flo_stream = { version = "0.4.0" }
futures = { version = "0.3.1" }
Expand Down
1 change: 1 addition & 0 deletions app/gui/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ ensogl::read_args! {
test_workflow : String,
skip_min_version_check : bool,
preferred_engine_version : semver::Version,
enable_new_component_browser : bool,
}
}
11 changes: 11 additions & 0 deletions app/gui/controller/double-representation/src/tp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ impl Display for QualifiedName {
}


// === Comparison ===

impl PartialEq<module::QualifiedName> for QualifiedName {
fn eq(&self, rhs: &module::QualifiedName) -> bool {
self.project_name == rhs.project_name
&& self.module_segments == rhs.id.parent_segments()
&& self.name == rhs.id.name().as_ref()
}
}



// =============
// === Tests ===
Expand Down
113 changes: 91 additions & 22 deletions app/gui/src/controller/searcher/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::prelude::*;

use crate::model::suggestion_database;

use convert_case::Case;
use convert_case::Casing;


// ==============
// === Export ===
Expand All @@ -29,6 +32,33 @@ pub type MatchInfo = controller::searcher::action::MatchInfo;



// ==============
// === Errors ===
// ==============

// === NoSuchGroup===

#[allow(missing_docs)]
#[derive(Clone, Debug, Fail)]
#[fail(display = "No component group with the index {} in section {}.", index, section_name)]
pub struct NoSuchGroup {
section_name: CowString,
index: usize,
}


// === NoSuchComponent ===

#[allow(missing_docs)]
#[derive(Clone, Debug, Fail)]
#[fail(display = "No component entry with the index {} in {}.", index, group_name)]
pub struct NoSuchComponent {
group_name: CowString,
index: usize,
}



// =============
// === Order ===
// =============
Expand All @@ -37,25 +67,18 @@ pub type MatchInfo = controller::searcher::action::MatchInfo;
/// [`Group::update_sorting_and_visibility`].
#[derive(Copy, Clone, Debug)]
pub enum Order {
/// The same order of components as when the group was built.
/// Will use the [`Group::initial_entries_order`] field.
Initial,
/// Order non-modules by name, followed by modules (also by name).
ByNameNonModulesThenModules,
/// Order [`Component`]s by [`Component::match_info`] score (best scores first).
/// Order [`Component`]s by [`Component::match_info`] score. The matching entries will go
/// first, and the _lesser_ score will take precedence. That is due to way of displaying
/// components in component browser - the lower (with greater indices) entries are more
/// handy.
ByMatch,
}

impl Order {
/// Compare two [`Component`]s according to [`Order`].
fn compare(&self, a: &Component, b: &Component) -> std::cmp::Ordering {
match self {
Order::ByNameNonModulesThenModules => {
let cmp_can_be_entered = a.can_be_entered().cmp(&b.can_be_entered());
cmp_can_be_entered.then_with(|| a.label().cmp(b.label()))
}
Order::ByMatch => a.match_info.borrow().cmp(&*b.match_info.borrow()).reverse(),
}
}
}



// =================
Expand Down Expand Up @@ -87,8 +110,8 @@ impl Component {
}

/// The label which should be displayed in the Component Browser.
pub fn label(&self) -> &str {
&self.suggestion.name
pub fn label(&self) -> String {
self.to_string()
}

/// Checks if component is filtered out.
Expand All @@ -109,7 +132,7 @@ impl Component {
/// It should be called each time the filtering pattern changes.
pub fn update_matching_info(&self, pattern: impl Str) {
let label = self.label();
let matches = fuzzly::matches(label, pattern.as_ref());
let matches = fuzzly::matches(&label, pattern.as_ref());
let subsequence = matches.and_option_from(|| {
let metric = fuzzly::metric::default();
fuzzly::find_best_subsequence(label, pattern, metric)
Expand All @@ -121,6 +144,20 @@ impl Component {
}
}

impl Display for Component {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let self_type_not_here =
self.suggestion.self_type.as_ref().filter(|t| *t != &self.suggestion.module);
if let Some(self_type) = self_type_not_here {
let self_name = self_type.name.from_case(Case::Snake).to_case(Case::Title);
let name = self.suggestion.name.from_case(Case::Snake).to_case(Case::Lower);
write!(f, "{} {}", self_name, name)
} else {
write!(f, "{}", self.suggestion.name.from_case(Case::Snake).to_case(Case::Lower))
}
}
}



// ============
Expand Down Expand Up @@ -190,20 +227,46 @@ impl List {
self.module_groups.get(&component).map(|mg| &mg.content)
}

/// Get the component from Top Modules by index.
pub fn top_module_entry_by_index(
&self,
group_index: usize,
entry_index: usize,
) -> FallibleResult<Component> {
self.top_modules().entry_by_index("Sub-modules".into(), group_index, entry_index)
}

/// Get the component from Favorites section by index.
pub fn favorites_entry_by_index(
&self,
group_index: usize,
entry_index: usize,
) -> FallibleResult<Component> {
self.favorites.entry_by_index("Favorites".into(), group_index, entry_index)
}

/// Get the component from Local Scope section by index.
pub fn local_scope_entry_by_index(&self, index: usize) -> FallibleResult<Component> {
let error =
|| NoSuchComponent { group_name: self.local_scope.name.to_string().into(), index };
self.local_scope.get_entry(index).ok_or_else(error).map_err(|e| e.into())
}

/// Update matching info in all components according to the new filtering pattern.
pub fn update_filtering(&self, pattern: impl AsRef<str>) {
let pattern = pattern.as_ref();
for component in &*self.all_components {
component.update_matching_info(pattern)
}
let pattern_not_empty = !pattern.is_empty();
let components_order =
let submodules_order =
if pattern_not_empty { Order::ByMatch } else { Order::ByNameNonModulesThenModules };
let favorites_order = if pattern_not_empty { Order::ByMatch } else { Order::Initial };
for group in self.all_groups_not_in_favorites() {
group.update_sorting_and_visibility(components_order);
group.update_sorting(submodules_order);
}
for group in self.favorites.iter() {
group.update_visibility();
group.update_sorting(favorites_order);
}
self.filtered.set(pattern_not_empty);
}
Expand Down Expand Up @@ -317,11 +380,10 @@ pub(crate) mod tests {
.entries
.borrow()
.iter()
.filter(|c| matches!(*c.match_info.borrow(), MatchInfo::Matches { .. }))
.take_while(|c| matches!(*c.match_info.borrow(), MatchInfo::Matches { .. }))
.map(|c| *c.id)
.collect_vec();
assert_eq!(ids_of_matches, expected_ids);
assert_eq!(group.visible.get(), !expected_ids.is_empty());
}

#[test]
Expand All @@ -343,6 +405,13 @@ pub(crate) mod tests {
let list = builder.build();

list.update_filtering("fu");
let match_infos = list.top_modules()[0]
.entries
.borrow()
.iter()
.map(|c| c.match_info.borrow().clone())
.collect_vec();
DEBUG!("{match_infos:?}");
assert_ids_of_matches_entries(&list.top_modules()[0], &[2, 3]);
assert_ids_of_matches_entries(&list.favorites[0], &[3, 2]);
assert_ids_of_matches_entries(&list.local_scope, &[2]);
Expand Down
Loading