Skip to content

Commit

Permalink
Fix atom types in dropdowns. (#7670)
Browse files Browse the repository at this point in the history
Fixes #7468

The fix is pretty simple: we reuse the existing functionality for importing stuff and generating expressions. It fixes issues with `Nothing` or `Report_Unmatched` types.


https://github.com/enso-org/enso/assets/6566674/4e7addf9-2175-4f2a-a571-4ef823de5cb0

While debugging, I found it easier to work with a suggestion database when exported to some external format. Hence, I implemented serde serialization support for database entries and also a new debug shortcut <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>u</kbd> to dump all entries to the console.
  • Loading branch information
vitvakatu authored Sep 5, 2023
1 parent abdbcfc commit 1f8675a
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 36 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
<kbd>enter</kbd>][7527]
- [Connections to lamdas are displayed correctly][7550]. It is possible to drag
a connection to any expression inside the lambda body.
- [Atom types in dropdowns do not produce redundant imports][#7670]. The
possibility of imports conflicts is reduced.
- [Copying and pasting a single node][7618]. Using the common
<kbd>cmd</kbd>+<kbd>C</kbd> and <kbd>cmd</kbd>+<kbd>V</kbd> shortcuts, it is
now possible to copy a single selected node and paste its code to the graph or
Expand Down Expand Up @@ -249,6 +251,7 @@
[7311]: https://github.com/enso-org/enso/pull/7311
[7527]: https://github.com/enso-org/enso/pull/7527
[7550]: https://github.com/enso-org/enso/pull/7550
[7670]: https://github.com/enso-org/enso/pull/7670
[7618]: https://github.com/enso-org/enso/pull/7618

#### EnsoGL (rendering engine)
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions app/gui/docs/product/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ broken and require further investigation.
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>arrow up</kbd> | Pop a breadcrumb without navigating. |
| <kbd>cmd</kbd> + <kbd>i</kbd> | Reload visualizations. To see the effect in the currently shown visualizations, you need to switch to another and switch back. |
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>b</kbd> | Toggle read-only mode. |
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>u</kbd> | Dump the suggestion database as JSON to the console. Available only in debug mode, and only if the component browser is open. |
5 changes: 5 additions & 0 deletions app/gui/src/controller/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ impl Searcher {
self
}

/// Dump the suggestion database to the console in JSON format.
pub fn dump_database_as_json(&self) {
console_log!("{}", self.database.dump_as_json());
}

/// Abort editing and perform cleanup.
pub fn abort_editing(&self) {
self.clear_temporary_imports();
Expand Down
11 changes: 0 additions & 11 deletions app/gui/src/presenter/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,6 @@ impl Model {
}
});
}

fn show_dashboard(&self) {
match enso_web::Event::new("show-dashboard") {
Ok(event) =>
if let Err(error) = enso_web::document.dispatch_event(&event) {
error!("Failed to dispatch event to show the dashboard. {error:?}");
},
Err(error) => error!("Failed to create event to show the dashboard. {error:?}"),
}
}
}


Expand Down Expand Up @@ -441,7 +431,6 @@ impl Project {
eval graph_view.execution_environment((env) model.execution_environment_changed(*env));
eval_ graph_view.execution_environment_play_button_pressed( model.trigger_clean_live_execution());

eval_ view.go_to_dashboard_button_pressed (model.show_dashboard());
eval view.current_shortcut ((shortcut) model.handled_shortcut_changed(shortcut));
}

Expand Down
1 change: 1 addition & 0 deletions app/gui/src/presenter/searcher/component_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl ComponentBrowserSearcher {
// must be up-to-date.
action_list_changed <+ model.project.searcher_input_changed.constant(());

eval_ model.project.request_dump_suggestion_database(model.controller.dump_database_as_json());
eval_ model.project.toggle_component_browser_private_entries_visibility (
model.controller.reload_list());
}
Expand Down
2 changes: 2 additions & 0 deletions app/gui/suggestion-database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ ensogl-icons = { path = "../../../lib/rust/ensogl/component/icons" }
flo_stream = { version = "0.4.0" }
failure = { workspace = true }
enso-notification = { path = "../../../lib/rust/notification" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[dev-dependencies]
futures = { workspace = true }
Expand Down
26 changes: 12 additions & 14 deletions app/gui/suggestion-database/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub struct ModuleSpan {
/// In order to make icon definitions more readable for non-programmer users, the builtin icon name
/// is allowed to be formatted in arbitrary casing. Either `SNAKE_case`,`camelCase`, `Pascal_Case`
/// etc. is allowed.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct IconName {
/// The name is kept in `PascalCase` to allow easy conversion into builtin icon ID.
pascal_cased: ImString,
Expand Down Expand Up @@ -176,7 +176,7 @@ impl From<Import> for import::Info {
// === Kind ===

/// A type of suggestion entry.
#[derive(Copy, Clone, Debug, Eq, PartialEq, ForEachVariant)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, ForEachVariant, serde::Serialize)]
#[allow(missing_docs)]
pub enum Kind {
Type,
Expand All @@ -195,7 +195,7 @@ pub enum Kind {
/// Methods are visible "Everywhere", as they are imported on a module level, so they are not
/// specific to any particular span in the module file.
/// However local variables and local function have limited visibility.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
pub enum Scope {
/// The entry is visible in the whole module where it was defined. It can be also brought to
/// other modules by import declarations.
Expand All @@ -214,7 +214,7 @@ pub enum Scope {
// === Entry ===

/// The Suggestion Database Entry.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
pub struct Entry {
/// A type of suggestion.
pub kind: Kind,
Expand Down Expand Up @@ -972,18 +972,16 @@ where
TagValueResolution::Resolved(entry, chain) => {
let label = chain_to_label(&chain);
let qualified_name = entry.qualified_name();
let parent_module = qualified_name.parent();
let required_import = parent_module.as_ref().map(|n| n.to_string());

let expression = if let Some(parent) = parent_module {
let in_module_name = qualified_name.name();
let parent_name = parent.name();
[parent_name, in_module_name].join(opr::predefined::ACCESS)
let required_import = Some(qualified_name.to_string());
// As we don't generate `this`, we will never follow the code path where
// `in_module` is used. That's why passing `default()` is valid.
let in_module = default();
let expression = entry.code_to_insert(false, in_module);
let expression = if entry.arguments.is_empty() {
expression.to_string()
} else {
qualified_name.to_string()
format!("({expression})")
};
let expression =
if entry.arguments.is_empty() { expression } else { format!("({expression})") };

span_tree::TagValue { required_import, expression, label: Some(label) }
}
Expand Down
7 changes: 7 additions & 0 deletions app/gui/suggestion-database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ impl SuggestionDatabase {
default()
}

/// Dump all entries in JSON.
pub fn dump_as_json(&self) -> String {
let all_entries: Vec<Entry> =
self.entries.borrow().values().map(|e| e.deref().clone()).collect_vec();
serde_json::to_string(&all_entries).unwrap()
}

/// Create a database filled with entries provided by the given iterator.
pub fn new_from_entries<'a>(
entries: impl IntoIterator<Item = (&'a SuggestionId, &'a Entry)>,
Expand Down
7 changes: 6 additions & 1 deletion app/gui/view/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ ensogl::define_endpoints! {
start_node_creation_with_component_browser(),
/// Accepts the currently selected input of the searcher.
accept_searcher_input(),
/// Dump the suggestion database in JSON to the console.
dump_suggestion_database(),
}

Output {
Expand All @@ -174,9 +176,10 @@ ensogl::define_endpoints! {
fullscreen_visualization_shown (bool),
drop_files_enabled (bool),
debug_mode (bool),
go_to_dashboard_button_pressed (),
/// The name of the command currently being handled due to shortcut being pressed.
current_shortcut (Option<ImString>),
/// Request the controller to dump the suggestion database in JSON to the console.
request_dump_suggestion_database(),
}
}

Expand Down Expand Up @@ -700,6 +703,7 @@ impl View {
debug_mode <- bool(&frp.disable_debug_mode, &frp.enable_debug_mode);
frp.source.debug_mode <+ debug_mode;
popup.is_enabled <+ debug_mode;
frp.source.request_dump_suggestion_database <+ frp.dump_suggestion_database;
}
self
}
Expand Down Expand Up @@ -803,6 +807,7 @@ impl application::View for View {
(Press, "is_searcher_opened", "enter", "accept_searcher_input"),
(Press, "debug_mode", "ctrl shift enter", "debug_push_breadcrumb"),
(Press, "debug_mode", "ctrl shift b", "debug_pop_breadcrumb"),
(Press, "debug_mode", "ctrl shift u", "dump_suggestion_database"),
]
.iter()
.map(|(a, b, c, d)| Self::self_shortcut_when(*a, *c, *d, *b))
Expand Down
1 change: 0 additions & 1 deletion lib/rust/font/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use derive_more::Deref;
use derive_more::Display;



// ==============
// === Export ===
// ==============
Expand Down
1 change: 1 addition & 0 deletions lib/rust/parser/doc-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enso-parser = { path = ".." }
enso-prelude = { path = "../../prelude" }
enso-profiler = { path = "../../profiler" }
enso-reflect = { path = "../../reflect" }
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
enso-metamodel = { path = "../../metamodel", features = ["rust"] }
Expand Down
4 changes: 2 additions & 2 deletions lib/rust/parser/doc-parser/src/doc_sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub type HtmlString = String;

/// A description of a single argument in the documentation. The name is delimited from the
/// description using a colon.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Clone, Hash, PartialEq, Eq, serde::Serialize)]
pub struct Argument {
/// Name of the argument.
pub name: String,
Expand All @@ -87,7 +87,7 @@ impl Argument {
}

/// A single section of the documentation.
#[derive(Hash, Debug, Clone, PartialEq, Eq)]
#[derive(Hash, Debug, Clone, PartialEq, Eq, serde::Serialize)]
#[allow(missing_docs)]
pub enum DocSection {
/// The documentation tag.
Expand Down
4 changes: 2 additions & 2 deletions lib/rust/parser/doc-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct TagWithDescription<'a, L> {
}

/// Indicator placed at the beginning of a documentation section, e.g. `PRIVATE`.
#[derive(Hash, Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Hash, Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
#[allow(missing_docs)]
pub enum Tag {
Added,
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct Marked<'a, L> {
}

/// Documentation section mark.
#[derive(Hash, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Hash, Debug, Copy, Clone, PartialEq, Eq, serde::Serialize)]
#[allow(missing_docs)]
pub enum Mark {
Important,
Expand Down
2 changes: 1 addition & 1 deletion lib/rust/text/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ crate-type = ["rlib", "cdylib"]
enso-prelude = { path = "../prelude" }
enso-types = { path = "../types" }
xi-rope = { version = "0.3.0" }
serde = "1"
serde = { version = "1", features = ["derive"] }
1 change: 1 addition & 0 deletions lib/rust/text/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ macro_rules! define_line_unit {
#[derive(
Clone, Copy, Debug, Display, Default, Eq, Hash, Ord, PartialEq, PartialOrd, From, Into
)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct $name {
#[allow(missing_docs)]
pub value: usize,
Expand Down
2 changes: 2 additions & 0 deletions lib/rust/text/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl AddAssign<usize> for Column {

unit! {
/// An offset in the text measured in number of code units in text in UTF-16 representation.
#[derive(serde::Serialize, serde::Deserialize)]
Utf16CodeUnit::utf16_code_unit(usize)
}

Expand All @@ -213,6 +214,7 @@ mod location {
use super::*;
#[doc = " A type representing 2d measurements."]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(missing_docs)]
pub struct Location<Offset = Column, LineType = Line> {
pub line: LineType,
Expand Down
7 changes: 3 additions & 4 deletions lib/rust/types/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ macro_rules! newtype_no_sub {
macro_rules! newtype_struct {
($(#$meta:tt)* $name:ident { $($field:ident : $field_type:ty),* $(,)? }) => {
$crate::newtype_struct_def! {$(#$meta)* $name { $($field : $field_type),*}}
$crate::newtype_struct_impls! {$(#$meta)* $name { $($field : $field_type),*}}
$crate::newtype_struct_impls! {$name { $($field : $field_type),*}}
}
}

Expand All @@ -410,7 +410,7 @@ macro_rules! newtype_struct {
macro_rules! newtype_struct_float_like {
($(#$meta:tt)* $name:ident { $($field:ident : $field_type:ty),* $(,)? }) => {
$crate::newtype_struct_def_float_like! {$(#$meta)* $name { $($field : $field_type),*}}
$crate::newtype_struct_impls! {$(#$meta)* $name { $($field : $field_type),*}}
$crate::newtype_struct_impls! {$name { $($field : $field_type),*}}
}
}

Expand Down Expand Up @@ -441,9 +441,8 @@ macro_rules! newtype_struct_def_float_like {
/// Unit definition macro. See module docs to learn more.
#[macro_export]
macro_rules! newtype_struct_impls {
($(#$meta:tt)* $name:ident { $field:ident : $field_type:ty $(,)? }) => {
($name:ident { $field:ident : $field_type:ty $(,)? }) => {
/// Smart constructor.
$(#$meta)*
#[allow(non_snake_case)]
pub const fn $name($field:$field_type) -> $name { $name {$field} }

Expand Down

0 comments on commit 1f8675a

Please sign in to comment.