From b0a5ac2c19fe848c5fd77e4bdbb1fe6fb8ae593c Mon Sep 17 00:00:00 2001 From: Ilya Bogdanov Date: Thu, 21 Sep 2023 12:33:53 +0400 Subject: [PATCH] Fix static methods in dropdowns (#7845) Fixes #7824 The issue was caused by me who didn't think that we can use static methods in dropdowns. https://github.com/enso-org/enso/assets/6566674/5045c5ce-e33b-48ff-9488-4228c016b563 --- .prettierignore | 1 + app/gui/src/controller/graph/executed.rs | 7 ++++-- app/gui/src/controller/graph/widget.rs | 2 ++ .../controller/graph/widget/configuration.rs | 23 +++++++++++++------ app/gui/src/test.rs | 6 +++-- app/gui/suggestion-database/src/entry.rs | 21 ++++++++++------- .../src/display/render/passes/cache_shapes.rs | 1 + .../core/src/display/render/passes/screen.rs | 1 + lib/rust/ensogl/core/src/display/scene.rs | 1 - .../ensogl/core/src/display/symbol/gpu.rs | 1 - lib/rust/ensogl/core/src/display/world.rs | 1 - .../core/src/system/gpu/data/texture.rs | 2 +- 12 files changed, 44 insertions(+), 23 deletions(-) diff --git a/.prettierignore b/.prettierignore index 55bc29de508..b6d5da58d68 100644 --- a/.prettierignore +++ b/.prettierignore @@ -29,6 +29,7 @@ test/**/data app/ide-desktop/build.json app/ide-desktop/lib/client/electron-builder-config.json app/gui/view/documentation/assets/stylesheet.css +app/gui2/rust-ffi/pkg Cargo.lock # Engine Builds can leave these nested working copies. diff --git a/app/gui/src/controller/graph/executed.rs b/app/gui/src/controller/graph/executed.rs index d922c512c56..fc447d071dc 100644 --- a/app/gui/src/controller/graph/executed.rs +++ b/app/gui/src/controller/graph/executed.rs @@ -513,8 +513,10 @@ impl Context for Handle { let info = self.computed_value_info_registry().get(&id)?; let method_call = info.method_call.as_ref()?; let suggestion_db = self.project.suggestion_db(); + let in_module = self.module_qualified_name(); let maybe_entry = suggestion_db.lookup_by_method_pointer(method_call).map(|(id, entry)| { - let invocation_info = entry.invocation_info(&suggestion_db, &self.parser()); + let invocation_info = + entry.invocation_info(&suggestion_db, &self.parser(), in_module.as_ref()); invocation_info.with_suggestion_id(id).with_called_on_type(false) }); @@ -526,7 +528,8 @@ impl Context for Handle { let defined_on_type = method_call.defined_on_type.strip_suffix(".type")?.to_owned(); let method_call = MethodPointer { defined_on_type, ..method_call.clone() }; let (id, entry) = suggestion_db.lookup_by_method_pointer(&method_call)?; - let invocation_info = entry.invocation_info(&suggestion_db, &self.parser()); + let invocation_info = + entry.invocation_info(&suggestion_db, &self.parser(), in_module.as_ref()); Some(invocation_info.with_suggestion_id(id).with_called_on_type(true)) }) } diff --git a/app/gui/src/controller/graph/widget.rs b/app/gui/src/controller/graph/widget.rs index 2496906417e..d7474243055 100644 --- a/app/gui/src/controller/graph/widget.rs +++ b/app/gui/src/controller/graph/widget.rs @@ -173,11 +173,13 @@ impl Model { data: VisualizationUpdateData, ) -> Option<(NodeId, CallWidgetsConfig)> { let query_data = self.widget_queries.get_mut(&target)?; + let in_module = self.graph.module_qualified_name(); let (definitions, errors) = configuration::deserialize_widget_definitions( &data, &self.graph.suggestion_db(), &self.graph.parser(), + in_module.as_ref(), ); for error in errors { diff --git a/app/gui/src/controller/graph/widget/configuration.rs b/app/gui/src/controller/graph/widget/configuration.rs index dff82bf92c1..9e3e065db03 100644 --- a/app/gui/src/controller/graph/widget/configuration.rs +++ b/app/gui/src/controller/graph/widget/configuration.rs @@ -7,6 +7,7 @@ use crate::model::execution_context::VisualizationUpdateData; use super::response; +use double_representation::name::QualifiedNameRef; use enso_suggestion_database::entry::argument_tag_values; use enso_suggestion_database::SuggestionDatabase; use ide_view::graph_editor::component::node::input::widget; @@ -27,6 +28,7 @@ pub fn deserialize_widget_definitions( data: &VisualizationUpdateData, db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> (Vec, Vec) { match serde_json::from_slice::(data) { Ok(response) => { @@ -35,7 +37,8 @@ pub fn deserialize_widget_definitions( let msg = "Failed to deserialize widget data for argument"; e.context(format!("{msg} '{}'", arg.name)) })?; - let meta = widget.map(|resp| to_configuration(resp, db, parser)); + let meta = + widget.map(|resp| to_configuration(resp, db, parser, in_module.clone_ref())); let argument_name = arg.name.into_owned(); Ok(ArgumentWidgetConfig { argument_name, config: meta }) }); @@ -58,10 +61,11 @@ fn to_configuration( resp: response::WidgetDefinition, db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> widget::Configuration { widget::Configuration { display: resp.display, - kind: to_kind(resp.inner, db, parser), + kind: to_kind(resp.inner, db, parser, in_module), has_port: true, } } @@ -70,10 +74,11 @@ fn to_kind( inner: response::WidgetKindDefinition, db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> widget::DynConfig { match inner { response::WidgetKindDefinition::SingleChoice { label, values } => { - let (choices, arguments) = to_choices_and_arguments(values, db, parser); + let (choices, arguments) = to_choices_and_arguments(values, db, parser, in_module); widget::single_choice::Config { label: label.map(Into::into), choices: Rc::new(choices), @@ -83,7 +88,7 @@ fn to_kind( } response::WidgetKindDefinition::ListEditor { item_widget, item_default } => widget::list_editor::Config { - item_widget: Some(Rc::new(to_configuration(*item_widget, db, parser))), + item_widget: Some(Rc::new(to_configuration(*item_widget, db, parser, in_module))), item_default: ImString::from(item_default).into(), } .into(), @@ -95,17 +100,20 @@ fn to_choices_and_arguments( choices: Vec, db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> (Vec, Vec) { let mut args = Vec::new(); let expressions = choices.iter().map(|c| c.value.as_ref()); - let as_tags = argument_tag_values(expressions, db, parser); + let as_tags = argument_tag_values(expressions, db, parser, in_module.clone_ref()); let entries = choices .into_iter() .enumerate() .zip(as_tags) - .map(|((index, choice), tag)| to_widget_choice(choice, index, db, parser, tag, &mut args)) + .map(|((index, choice), tag)| { + to_widget_choice(choice, index, db, parser, tag, &mut args, in_module.clone_ref()) + }) .collect(); (entries, args) } @@ -117,6 +125,7 @@ fn to_widget_choice( parser: &parser::Parser, tag: span_tree::TagValue, arguments: &mut Vec, + in_module: QualifiedNameRef, ) -> widget::Choice { let value: ImString = tag.expression.into(); let label = choice.label.map_or_else(|| value.clone(), |label| label.into()); @@ -126,7 +135,7 @@ fn to_widget_choice( match arg.data.widget { Ok(None) => {} Ok(Some(config)) => { - let configuration = to_configuration(config, db, parser); + let configuration = to_configuration(config, db, parser, in_module.clone_ref()); let arg = widget::single_choice::ChoiceArgConfig { choice_index, name: arg.name.into(), diff --git a/app/gui/src/test.rs b/app/gui/src/test.rs index f51cad2c5d9..86dfc2b057b 100644 --- a/app/gui/src/test.rs +++ b/app/gui/src/test.rs @@ -460,8 +460,10 @@ pub fn assert_call_info( let parser = parser::Parser::new(); let db = model::suggestion_database::SuggestionDatabase::new_empty(); for (encountered, expected) in info.parameters.iter().zip(entry.arguments.iter()) { - let expected_info = - model::suggestion_database::entry::to_span_tree_param(expected, &db, &parser); + let in_module = default(); + let expected_info = model::suggestion_database::entry::to_span_tree_param( + expected, &db, &parser, in_module, + ); assert_eq!(encountered, &expected_info); } } diff --git a/app/gui/suggestion-database/src/entry.rs b/app/gui/suggestion-database/src/entry.rs index 71cd66c13b0..1ec3969efde 100644 --- a/app/gui/suggestion-database/src/entry.rs +++ b/app/gui/suggestion-database/src/entry.rs @@ -575,11 +575,12 @@ impl Entry { &self, suggestion_db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> span_tree::generate::context::CalledMethodInfo { let parameters = self .arguments .iter() - .map(|arg| to_span_tree_param(arg, suggestion_db, parser)) + .map(|arg| to_span_tree_param(arg, suggestion_db, parser, in_module.clone_ref())) .collect(); span_tree::generate::context::CalledMethodInfo { is_static: self.is_static, @@ -896,9 +897,14 @@ pub fn to_span_tree_param( param_info: &Argument, db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> span_tree::ArgumentInfo { - let tag_values = - argument_tag_values(param_info.tag_values.iter().map(|s| s.as_str()), db, parser); + let tag_values = argument_tag_values( + param_info.tag_values.iter().map(|s| s.as_str()), + db, + parser, + in_module, + ); span_tree::ArgumentInfo { // TODO [mwu] Check if database actually do must always have both of these filled. name: Some(param_info.name.clone()), @@ -955,6 +961,7 @@ pub fn argument_tag_values<'a, E>( raw_expressions: E, db: &SuggestionDatabase, parser: &parser::Parser, + in_module: QualifiedNameRef, ) -> Vec where E: IntoIterator, @@ -973,10 +980,7 @@ where let label = chain_to_label(&chain); let qualified_name = entry.qualified_name(); 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 = entry.code_to_insert(true, in_module.clone_ref()); let expression = if entry.arguments.is_empty() { expression.to_string() } else { @@ -1463,7 +1467,8 @@ mod test { let parser = Parser::new(); let db = SuggestionDatabase::new_empty(); let expressions = expression_and_expected_label.iter().map(|(expr, _)| *expr); - let tag_values = argument_tag_values(expressions, &db, &parser); + let in_module = default(); + let tag_values = argument_tag_values(expressions, &db, &parser, in_module); let expected_values = expression_and_expected_label .iter() .map(|(expression, label)| span_tree::TagValue { diff --git a/lib/rust/ensogl/core/src/display/render/passes/cache_shapes.rs b/lib/rust/ensogl/core/src/display/render/passes/cache_shapes.rs index da36b0a752d..b00ef89bf67 100644 --- a/lib/rust/ensogl/core/src/display/render/passes/cache_shapes.rs +++ b/lib/rust/ensogl/core/src/display/render/passes/cache_shapes.rs @@ -13,6 +13,7 @@ use crate::gui::component::AnyShapeView; use crate::system::gpu::context::ContextLost; + // ========================== // === CacheShapesPassDef === // ========================== diff --git a/lib/rust/ensogl/core/src/display/render/passes/screen.rs b/lib/rust/ensogl/core/src/display/render/passes/screen.rs index 34e5776a5e3..2ae6a62253f 100644 --- a/lib/rust/ensogl/core/src/display/render/passes/screen.rs +++ b/lib/rust/ensogl/core/src/display/render/passes/screen.rs @@ -8,6 +8,7 @@ use crate::display::symbol::Screen; use crate::system::gpu::context::ContextLost; + // ======================== // === ScreenRenderPass === // ======================== diff --git a/lib/rust/ensogl/core/src/display/scene.rs b/lib/rust/ensogl/core/src/display/scene.rs index 56f445d42c1..e3f3a74f63a 100644 --- a/lib/rust/ensogl/core/src/display/scene.rs +++ b/lib/rust/ensogl/core/src/display/scene.rs @@ -43,7 +43,6 @@ use std::any::TypeId; use web::HtmlElement; - // ============== // === Export === // ============== diff --git a/lib/rust/ensogl/core/src/display/symbol/gpu.rs b/lib/rust/ensogl/core/src/display/symbol/gpu.rs index 892cc59282e..15b81afb9b7 100644 --- a/lib/rust/ensogl/core/src/display/symbol/gpu.rs +++ b/lib/rust/ensogl/core/src/display/symbol/gpu.rs @@ -27,7 +27,6 @@ use web_sys::WebGlUniformLocation; use web_sys::WebGlVertexArrayObject; - // ============== // === Export === // ============== diff --git a/lib/rust/ensogl/core/src/display/world.rs b/lib/rust/ensogl/core/src/display/world.rs index 2aad127ca67..d99bc49a199 100644 --- a/lib/rust/ensogl/core/src/display/world.rs +++ b/lib/rust/ensogl/core/src/display/world.rs @@ -34,7 +34,6 @@ use web::JsCast; use web::JsValue; - // ============== // === Export === // ============== diff --git a/lib/rust/ensogl/core/src/system/gpu/data/texture.rs b/lib/rust/ensogl/core/src/system/gpu/data/texture.rs index b741b0c89d9..0c6ddbeb440 100644 --- a/lib/rust/ensogl/core/src/system/gpu/data/texture.rs +++ b/lib/rust/ensogl/core/src/system/gpu/data/texture.rs @@ -13,7 +13,6 @@ use crate::system::gpu::Context; use web_sys::WebGlTexture; - // ============== // === Export === // ============== @@ -23,6 +22,7 @@ pub mod types; pub use types::*; + /// Provides smart scope for item types. pub mod item_type { pub use super::types::item_type::AnyItemType::*;