From 9b30f3b9e0d0b94f808adc690dafd994762986a8 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 28 Sep 2022 17:31:13 +0300 Subject: [PATCH 1/9] feat: remove here keyword --- app/gui/controller/double-representation/src/module.rs | 9 +++------ .../double-representation/src/refactorings/collapse.rs | 5 +---- app/gui/language/ast/impl/src/lib.rs | 2 -- app/gui/src/controller/searcher.rs | 7 ++----- app/gui/src/model/suggestion_database/entry.rs | 7 +++---- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/app/gui/controller/double-representation/src/module.rs b/app/gui/controller/double-representation/src/module.rs index 0b402032976f..63419176b8da 100644 --- a/app/gui/controller/double-representation/src/module.rs +++ b/app/gui/controller/double-representation/src/module.rs @@ -13,7 +13,6 @@ use crate::identifier::ReferentName; use crate::project; use crate::tp; -use ast::constants::keywords::HERE; use ast::constants::PROJECTS_MAIN_MODULE; use ast::crumbs::ChildAst; use ast::crumbs::ModuleCrumb; @@ -780,15 +779,14 @@ pub fn locate( /// The module is assumed to be in the file identified by the `method.file` (for the purpose of /// desugaring implicit extensions methods for modules). /// -/// The `module_name` parameter is the name of the module that contains `ast`. It affects how the -/// `here` keyword is resolved. +/// The `module_name` parameter is the name of the module that contains `ast`. pub fn lookup_method( module_name: &QualifiedName, ast: &known::Module, method: &language_server::MethodPointer, ) -> FallibleResult { let qualified_typename = tp::QualifiedName::from_text(&method.defined_on_type)?; - let accept_here_methods = module_name == &qualified_typename; + let defined_in_this_module = module_name == &qualified_typename; let method_module_name = QualifiedName::try_from(method)?; let implicit_extension_allowed = method.defined_on_type == method_module_name.to_string(); for child in ast.def_iter() { @@ -798,8 +796,7 @@ pub fn lookup_method( [] => implicit_extension_allowed, [typename] => { let explicit_type_matching = typename.item == qualified_typename.name; - let here_extension_matching = typename.item == HERE && accept_here_methods; - explicit_type_matching || here_extension_matching + explicit_type_matching || defined_in_this_module } _ => child_name.explicitly_extends_type(&method.defined_on_type), }; diff --git a/app/gui/controller/double-representation/src/refactorings/collapse.rs b/app/gui/controller/double-representation/src/refactorings/collapse.rs index 49e1ddc5bd69..4d28dc306058 100644 --- a/app/gui/controller/double-representation/src/refactorings/collapse.rs +++ b/app/gui/controller/double-representation/src/refactorings/collapse.rs @@ -14,8 +14,6 @@ use crate::node; use crate::node::MainLine; use crate::node::NodeInfo; -use ast::constants::keywords::HERE; -use ast::crumbs::Located; use ast::BlockLine; use parser::Parser; use std::collections::BTreeSet; @@ -320,8 +318,7 @@ impl Collapser { /// Does not include any pattern for assigning the resulting value. pub fn call_to_extracted(&self, extracted: &definition::ToAdd) -> FallibleResult { // TODO actually check that generated name is single-identifier - let mut target = extracted.name.clone(); - target.extended_target.insert(0, Located::new_root(HERE.to_string())); + let target = extracted.name.clone(); let base = target.ast(&self.parser)?; let args = extracted.explicit_parameter_names.iter().map(Ast::var); let chain = ast::prefix::Chain::new(base, args); diff --git a/app/gui/language/ast/impl/src/lib.rs b/app/gui/language/ast/impl/src/lib.rs index b9ab9fc42ce2..090b79800f1b 100644 --- a/app/gui/language/ast/impl/src/lib.rs +++ b/app/gui/language/ast/impl/src/lib.rs @@ -65,8 +65,6 @@ pub mod constants { /// A module with language-specific constants. pub mod keywords { - /// A keyword indicating current module. - pub const HERE: &str = "here"; /// The "void" atom returned by function meant to not return any argument. pub const NOTHING: &str = "Nothing"; diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 1925998a4c42..0778c5861404 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -955,9 +955,8 @@ impl Searcher { // === Add new node === - let here = Ast::var(ast::constants::keywords::HERE); let args = std::iter::empty(); - let node_expression = ast::prefix::Chain::new_with_this(new_definition_name, here, args); + let node_expression = ast::prefix::Chain::new(new_definition_name, args); let node_expression = node_expression.into_ast(); let node = NodeInfo::from_main_line_ast(&node_expression).ok_or(FailedToCreateNode)?; let added_node_id = node.id(); @@ -1247,9 +1246,7 @@ impl Searcher { self.database.lookup_locals_by_name_and_location(this_name, &module_name, position); let not_local_name = matching_locals.is_empty(); not_local_name.and_option_from(|| { - if this_name == ast::constants::keywords::HERE - || this_name == module_name.name().deref() - { + if this_name == module_name.name().deref() { Some(module_name) } else { self.module().iter_imports().find_map(|import| { diff --git a/app/gui/src/model/suggestion_database/entry.rs b/app/gui/src/model/suggestion_database/entry.rs index d36a3f4da53f..f7a6ba46a506 100644 --- a/app/gui/src/model/suggestion_database/entry.rs +++ b/app/gui/src/model/suggestion_database/entry.rs @@ -4,7 +4,6 @@ use crate::prelude::*; use crate::model::module::MethodId; -use ast::constants::keywords; use convert_case::Case; use convert_case::Casing; use double_representation::module; @@ -261,14 +260,14 @@ impl Entry { imports.insert(self.module.clone()); } - let this_expr = if generate_this { + let this_expr: Option = if generate_this { // TODO [mwu] Currently we support `self` generation for module atoms only. // This should be extended to any atom that is known to be nullary. // Tracked by https://github.com/enso-org/ide/issues/1299 if self.is_regular_module_method() { if is_local_entry { - // No additional import for `here`. - Some(keywords::HERE.to_owned()) + // No additional import for entries defined in this module. + None } else { // If we are inserting an additional `self` argument, the used name must be // visible. From cffbf6372850d0644698a29fd2bb1bb1db62bfca Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Wed, 28 Sep 2022 18:03:50 +0300 Subject: [PATCH 2/9] test: fix suggestion tests --- app/gui/src/model/suggestion_database/entry.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/gui/src/model/suggestion_database/entry.rs b/app/gui/src/model/suggestion_database/entry.rs index f7a6ba46a506..2e49c3c8b88f 100644 --- a/app/gui/src/model/suggestion_database/entry.rs +++ b/app/gui/src/model/suggestion_database/entry.rs @@ -790,7 +790,7 @@ mod test { expect(&module_method, None, true, "Project.module_method", &[&main_module]); expect(&module_method, None, false, "module_method", &[]); - expect(&module_method, Some(&main_module), true, "here.module_method", &[]); + expect(&module_method, Some(&main_module), true, "module_method", &[]); expect(&module_method, Some(&main_module), false, "module_method", &[]); expect(&module_method, Some(&another_module), true, "Project.module_method", &[ &main_module, @@ -809,7 +809,7 @@ mod test { &[&another_module], ); expect(&another_module_method, Some(&main_module), false, "module_method", &[]); - expect(&another_module_method, Some(&another_module), true, "here.module_method", &[]); + expect(&another_module_method, Some(&another_module), true, "module_method", &[]); expect(&another_module_method, Some(&another_module), false, "module_method", &[]); // TODO [mwu] Extensions on nullary atoms should also be able to generate this. From 0146942edb6268add3553ec0cdfbf1fb68107f68 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 12:27:44 +0300 Subject: [PATCH 3/9] feat: insert module name --- .../src/refactorings/collapse.rs | 28 +++++++++++++------ app/gui/src/controller/graph.rs | 3 +- app/gui/src/controller/searcher.rs | 4 ++- app/gui/src/model/module.rs | 3 ++ app/gui/src/model/module/plain.rs | 5 ++++ app/gui/src/model/module/synchronized.rs | 5 ++++ .../src/model/suggestion_database/entry.rs | 12 ++++++-- 7 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/gui/controller/double-representation/src/refactorings/collapse.rs b/app/gui/controller/double-representation/src/refactorings/collapse.rs index 4d28dc306058..8d733d2f6439 100644 --- a/app/gui/controller/double-representation/src/refactorings/collapse.rs +++ b/app/gui/controller/double-representation/src/refactorings/collapse.rs @@ -10,10 +10,12 @@ use crate::definition; use crate::definition::DefinitionInfo; use crate::graph::GraphInfo; use crate::identifier::Identifier; +use crate::identifier::ReferentName; use crate::node; use crate::node::MainLine; use crate::node::NodeInfo; +use ast::crumbs::Located; use ast::BlockLine; use parser::Parser; use std::collections::BTreeSet; @@ -39,8 +41,9 @@ pub fn collapse( selected_nodes: impl IntoIterator, name: Identifier, parser: &Parser, + module_name: ReferentName, ) -> FallibleResult { - Collapser::new(graph.clone(), selected_nodes, parser.clone_ref())?.collapse(name) + Collapser::new(graph.clone(), selected_nodes, parser.clone_ref(), module_name)?.collapse(name) } @@ -295,6 +298,7 @@ pub struct Collapser { parser: Parser, /// Identifier of the node to be introduced as a result of collapsing. collapsed_node: node::Id, + module_name: ReferentName, } impl Collapser { @@ -304,13 +308,14 @@ impl Collapser { graph: GraphInfo, selected_nodes: impl IntoIterator, parser: Parser, + module_name: ReferentName, ) -> FallibleResult { let graph = GraphHelper::new(graph); let extracted = Extracted::new(&graph, selected_nodes)?; let last_selected = extracted.extracted_nodes.iter().last().ok_or(NoNodesSelected)?.id(); let replaced_node = extracted.output.as_ref().map(|out| out.node).unwrap_or(last_selected); let collapsed_node = node::Id::new_v4(); - Ok(Collapser { graph, extracted, replaced_node, parser, collapsed_node }) + Ok(Collapser { graph, extracted, replaced_node, parser, collapsed_node, module_name }) } /// Generate the expression that calls the extracted method definition. @@ -318,7 +323,8 @@ impl Collapser { /// Does not include any pattern for assigning the resulting value. pub fn call_to_extracted(&self, extracted: &definition::ToAdd) -> FallibleResult { // TODO actually check that generated name is single-identifier - let target = extracted.name.clone(); + let mut target = extracted.name.clone(); + target.extended_target.insert(0, Located::new_root(self.module_name.clone().into())); let base = target.ast(&self.parser)?; let args = extracted.explicit_parameter_names.iter().map(Ast::var); let chain = ast::prefix::Chain::new(base, args); @@ -386,6 +392,7 @@ mod tests { use ast::crumbs::Crumb; struct Case { + module_name: ReferentName, refactored_name: DefinitionName, introduced_name: Identifier, initial_method_code: &'static str, @@ -405,7 +412,8 @@ mod tests { ast::test_utils::assert_unique_ids(ast.as_ref()); let selection = selection.iter().copied(); let new_name = self.introduced_name.clone(); - let collapsed = collapse(&graph, selection, new_name, parser).unwrap(); + let module_name = self.module_name.clone(); + let collapsed = collapse(&graph, selection, new_name, parser, module_name).unwrap(); let new_method = collapsed.new_method.ast(0, parser).unwrap(); let placement = module::Placement::Before(self.refactored_name.clone()); let new_main = &collapsed.updated_definition.ast; @@ -438,6 +446,7 @@ mod tests { #[wasm_bindgen_test] fn test_collapse() { let parser = Parser::new_or_panic(); + let module_name = ReferentName::new("Main".to_owned()).unwrap(); let introduced_name = Identifier::try_from("custom_new").unwrap(); let refactored_name = DefinitionName::new_plain("custom_old"); let initial_method_code = r"custom_old = @@ -454,10 +463,11 @@ mod tests { c"; let expected_refactored = r"custom_old = a = 1 - c = here.custom_new a + c = Main.custom_new a c + 7"; let mut case = Case { + module_name, refactored_name, introduced_name, initial_method_code, @@ -480,7 +490,7 @@ mod tests { a = 1 b = 2 c = A + B - d = here.custom_new a b + d = Main.custom_new a b c + 7"; case.run(&parser); @@ -499,7 +509,7 @@ mod tests { a = 1 b = 2 c = A + B - here.custom_new a b + Main.custom_new a b c + 7"; case.run(&parser); @@ -515,7 +525,7 @@ mod tests { c = 50 + d c"; case.expected_refactored = r"custom_old = - c = here.custom_new + c = Main.custom_new c + c + 10"; case.run(&parser); @@ -534,7 +544,7 @@ mod tests { case.expected_refactored = r"custom_old = number1 = 1 number2 = 2 - vector = here.custom_new number1 number2"; + vector = Main.custom_new number1 number2"; case.run(&parser); } } diff --git a/app/gui/src/controller/graph.rs b/app/gui/src/controller/graph.rs index 207def6b2fbd..af7c72dd1986 100644 --- a/app/gui/src/controller/graph.rs +++ b/app/gui/src/controller/graph.rs @@ -897,7 +897,8 @@ impl Handle { let introduced_name = module.generate_name(new_method_name_base)?; let node_ids = nodes.iter().map(|node| node.info.id()); let graph = self.graph_info()?; - let collapsed = collapse(&graph, node_ids, introduced_name, &self.parser)?; + let module_name = self.module.name(); + let collapsed = collapse(&graph, node_ids, introduced_name, &self.parser, module_name)?; let Collapsed { new_method, updated_definition, collapsed_node } = collapsed; let graph = self.graph_info()?; diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 0778c5861404..934338184e60 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -956,7 +956,9 @@ impl Searcher { // === Add new node === let args = std::iter::empty(); - let node_expression = ast::prefix::Chain::new(new_definition_name, args); + let this_expression = Ast::var(self.module_qualified_name().name()); + let node_expression = + ast::prefix::Chain::new_with_this(new_definition_name, this_expression, args); let node_expression = node_expression.into_ast(); let node = NodeInfo::from_main_line_ast(&node_expression).ok_or(FailedToCreateNode)?; let added_node_id = node.id(); diff --git a/app/gui/src/model/module.rs b/app/gui/src/model/module.rs index 8811d087c7a3..ab7435e6aa5e 100644 --- a/app/gui/src/model/module.rs +++ b/app/gui/src/model/module.rs @@ -550,6 +550,9 @@ pub trait API: Debug + model::undo_redo::Aware { /// Get the module path. fn path(&self) -> &Path; + /// Get the module name. + fn name(&self) -> ReferentName; + /// Get module sources as a string, which contains both code and metadata. fn serialized_content(&self) -> FallibleResult; diff --git a/app/gui/src/model/module/plain.rs b/app/gui/src/model/module/plain.rs index 0c0fd2c458d9..60cc89168aa4 100644 --- a/app/gui/src/model/module/plain.rs +++ b/app/gui/src/model/module/plain.rs @@ -16,6 +16,7 @@ use crate::model::module::TextChange; use crate::notification; use double_representation::definition::DefinitionInfo; +use double_representation::identifier::ReferentName; use double_representation::module::ImportId; use flo_stream::Subscriber; use parser::api::ParsedSourceFile; @@ -136,6 +137,10 @@ impl model::module::API for Module { &self.path } + fn name(&self) -> ReferentName { + self.path.module_name() + } + fn serialized_content(&self) -> FallibleResult { self.content.borrow().serialize().map_err(|e| e.into()) } diff --git a/app/gui/src/model/module/synchronized.rs b/app/gui/src/model/module/synchronized.rs index 447f78ef5faf..601ad91e790d 100644 --- a/app/gui/src/model/module/synchronized.rs +++ b/app/gui/src/model/module/synchronized.rs @@ -16,6 +16,7 @@ use crate::model::module::API; use ast::IdMap; use double_representation::definition::DefinitionInfo; use double_representation::graph::Id; +use double_representation::identifier::ReferentName; use double_representation::module::ImportId; use engine_protocol::language_server; use engine_protocol::language_server::TextEdit; @@ -194,6 +195,10 @@ impl API for Module { self.model.path() } + fn name(&self) -> ReferentName { + self.path().module_name() + } + fn serialized_content(&self) -> FallibleResult { self.model.serialized_content() } diff --git a/app/gui/src/model/suggestion_database/entry.rs b/app/gui/src/model/suggestion_database/entry.rs index 2e49c3c8b88f..1e0cb13c57d8 100644 --- a/app/gui/src/model/suggestion_database/entry.rs +++ b/app/gui/src/model/suggestion_database/entry.rs @@ -267,7 +267,7 @@ impl Entry { if self.is_regular_module_method() { if is_local_entry { // No additional import for entries defined in this module. - None + Some(self.module.name().into()) } else { // If we are inserting an additional `self` argument, the used name must be // visible. @@ -790,7 +790,7 @@ mod test { expect(&module_method, None, true, "Project.module_method", &[&main_module]); expect(&module_method, None, false, "module_method", &[]); - expect(&module_method, Some(&main_module), true, "module_method", &[]); + expect(&module_method, Some(&main_module), true, "Main.module_method", &[]); expect(&module_method, Some(&main_module), false, "module_method", &[]); expect(&module_method, Some(&another_module), true, "Project.module_method", &[ &main_module, @@ -809,7 +809,13 @@ mod test { &[&another_module], ); expect(&another_module_method, Some(&main_module), false, "module_method", &[]); - expect(&another_module_method, Some(&another_module), true, "module_method", &[]); + expect( + &another_module_method, + Some(&another_module), + true, + "Another_Module.module_method", + &[], + ); expect(&another_module_method, Some(&another_module), false, "module_method", &[]); // TODO [mwu] Extensions on nullary atoms should also be able to generate this. From 0f312b9c73b0a2c595a93a1a44cd9a47ec2e3fb9 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 15:36:36 +0300 Subject: [PATCH 4/9] misc: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8653d926509..c987a5e81a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ - [Selecting a suggestion from the searcher or component browser now updates the visualisation of the edited node to preview the results of applying the suggestion.][3691] +- [Remove here keyword from IDE.][3749] #### EnsoGL (rendering engine) @@ -326,6 +327,7 @@ [3726]: https://github.com/enso-org/enso/pull/3726 [3727]: https://github.com/enso-org/enso/pull/3727 [3733]: https://github.com/enso-org/enso/pull/3733 +[3749]: https://github.com/enso-org/enso/pull/3749 #### Enso Compiler From ed7ee2d616e9ecabe50b943ebcaf0d19bbafb9ba Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 16:13:07 +0300 Subject: [PATCH 5/9] feat: name default impl --- app/gui/src/model/module.rs | 4 +++- app/gui/src/model/module/plain.rs | 4 ---- app/gui/src/model/module/synchronized.rs | 4 ---- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/gui/src/model/module.rs b/app/gui/src/model/module.rs index ab7435e6aa5e..fb6e455a8177 100644 --- a/app/gui/src/model/module.rs +++ b/app/gui/src/model/module.rs @@ -551,7 +551,9 @@ pub trait API: Debug + model::undo_redo::Aware { fn path(&self) -> &Path; /// Get the module name. - fn name(&self) -> ReferentName; + fn name(&self) -> ReferentName { + self.path().module_name() + } /// Get module sources as a string, which contains both code and metadata. fn serialized_content(&self) -> FallibleResult; diff --git a/app/gui/src/model/module/plain.rs b/app/gui/src/model/module/plain.rs index 60cc89168aa4..246eb4e04012 100644 --- a/app/gui/src/model/module/plain.rs +++ b/app/gui/src/model/module/plain.rs @@ -137,10 +137,6 @@ impl model::module::API for Module { &self.path } - fn name(&self) -> ReferentName { - self.path.module_name() - } - fn serialized_content(&self) -> FallibleResult { self.content.borrow().serialize().map_err(|e| e.into()) } diff --git a/app/gui/src/model/module/synchronized.rs b/app/gui/src/model/module/synchronized.rs index 601ad91e790d..8e049da95fcd 100644 --- a/app/gui/src/model/module/synchronized.rs +++ b/app/gui/src/model/module/synchronized.rs @@ -195,10 +195,6 @@ impl API for Module { self.model.path() } - fn name(&self) -> ReferentName { - self.path().module_name() - } - fn serialized_content(&self) -> FallibleResult { self.model.serialized_content() } From 69db9b2ad93214a52b9bd90dc83cf3eb31a84cbc Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 16:13:56 +0300 Subject: [PATCH 6/9] misc: cleanup --- app/gui/src/model/module/plain.rs | 1 - app/gui/src/model/module/synchronized.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/app/gui/src/model/module/plain.rs b/app/gui/src/model/module/plain.rs index 246eb4e04012..0c0fd2c458d9 100644 --- a/app/gui/src/model/module/plain.rs +++ b/app/gui/src/model/module/plain.rs @@ -16,7 +16,6 @@ use crate::model::module::TextChange; use crate::notification; use double_representation::definition::DefinitionInfo; -use double_representation::identifier::ReferentName; use double_representation::module::ImportId; use flo_stream::Subscriber; use parser::api::ParsedSourceFile; diff --git a/app/gui/src/model/module/synchronized.rs b/app/gui/src/model/module/synchronized.rs index 8e049da95fcd..447f78ef5faf 100644 --- a/app/gui/src/model/module/synchronized.rs +++ b/app/gui/src/model/module/synchronized.rs @@ -16,7 +16,6 @@ use crate::model::module::API; use ast::IdMap; use double_representation::definition::DefinitionInfo; use double_representation::graph::Id; -use double_representation::identifier::ReferentName; use double_representation::module::ImportId; use engine_protocol::language_server; use engine_protocol::language_server::TextEdit; From 636310f7b3086cf7724ced50a21bb7a7d926af24 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 16:47:08 +0300 Subject: [PATCH 7/9] fix: searcher tests --- app/gui/src/controller/searcher.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 934338184e60..5f0a004a699a 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1961,7 +1961,6 @@ pub mod test { // Known functions cases searcher.set_input("Test.testMethod1 ".to_string()).unwrap(); - searcher.set_input("here.testMethod1 ".to_string()).unwrap(); searcher.set_input(iformat!("{MODULE_NAME}.testMethod1 ")).unwrap(); searcher.set_input("testFunction2 \"str\" ".to_string()).unwrap(); @@ -2517,7 +2516,7 @@ pub mod test { documentation_html: "Lorem ipsum".to_owned(), }; let expected_code = "test_example1 =\n x = 2 + 2\n x + 4\n\n\ - main = \n 2 + 2\n here.test_example1"; + main = \n 2 + 2\n Mock_Module.test_example1"; searcher.add_example(&Rc::new(example)).unwrap(); assert_eq!(module.ast().repr(), expected_code); } @@ -2534,7 +2533,7 @@ pub mod test { }; let expected_code = "import std.Base.Network.Http\n\ test_example1 = [1,2,3,4,5]\n\ntest_example2 = [1,2,3,4,5]\n\n\ - main = \n 2 + 2\n here.test_example1\n here.test_example2"; + main = \n 2 + 2\n Mock_Module.test_example1\n Mock_Module.test_example2"; let example = Rc::new(example); searcher.add_example(&example).unwrap(); searcher.add_example(&example).unwrap(); From a0c7467292a72a0d6944338e06c2c0b30707da2d Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 20:03:14 +0300 Subject: [PATCH 8/9] fix: wasm tests --- .../controller/double-representation/src/module.rs | 12 ++++-------- app/gui/src/controller/graph.rs | 4 ++-- app/gui/src/controller/searcher.rs | 1 - 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/gui/controller/double-representation/src/module.rs b/app/gui/controller/double-representation/src/module.rs index 63419176b8da..a97c6e8ee873 100644 --- a/app/gui/controller/double-representation/src/module.rs +++ b/app/gui/controller/double-representation/src/module.rs @@ -949,9 +949,6 @@ mod tests { // Explicit module extension method. let id = definition::Id::new_single_crumb(DefinitionName::new_method("Main", "foo")); expect_find(&ptr, "Main.foo a b = a + b", &id); - // Explicit extensions using "here" keyword. - let id = definition::Id::new_single_crumb(DefinitionName::new_method("here", "foo")); - expect_find(&ptr, "here.foo a b = a + b", &id); // Matching name but extending wrong type. expect_not_found(&ptr, "Number.foo a b = a + b"); // Mismatched name. @@ -970,7 +967,6 @@ mod tests { let id = definition::Id::new_single_crumb(DefinitionName::new_method("Number", "foo")); expect_find(&ptr, "Number.foo a b = a + b", &id); expect_not_found(&ptr, "Text.foo a b = a + b"); - expect_not_found(&ptr, "here.foo a b = a + b"); expect_not_found(&ptr, "bar a b = a + b"); } @@ -1012,7 +1008,7 @@ last def = inline expression"; let parser = parser::Parser::new_or_panic(); let module = r#"Main.method1 arg = body -main = here.method1 10"#; +main = Main.method1 10"#; let module = Info::from(parser.parse_module(module, default()).unwrap()); let method1_id = DefinitionName::new_method("Main", "method1"); @@ -1034,12 +1030,12 @@ main = here.method1 10"#; Main.method1 arg = body -main = here.method1 10"#; +main = Main.method1 10"#; assert_eq!(repr_after_insertion(Placement::Begin), expected); let expected = r#"Main.method1 arg = body -main = here.method1 10 +main = Main.method1 10 Main.add arg1 arg2 = arg1 + arg2"#; assert_eq!(repr_after_insertion(Placement::End), expected); @@ -1048,7 +1044,7 @@ Main.add arg1 arg2 = arg1 + arg2"#; Main.add arg1 arg2 = arg1 + arg2 -main = here.method1 10"#; +main = Main.method1 10"#; assert_eq!(repr_after_insertion(Placement::After(method1_id.clone())), expected); assert_eq!( diff --git a/app/gui/src/controller/graph.rs b/app/gui/src/controller/graph.rs index af7c72dd1986..9d29c3ea5cb9 100644 --- a/app/gui/src/controller/graph.rs +++ b/app/gui/src/controller/graph.rs @@ -1276,7 +1276,7 @@ func3 a = main = a = 10 - here.func3 a + Mock_Module.func3 a a + func1"; test.data.code = code.to_owned(); @@ -1304,7 +1304,7 @@ func1 = a main = - a = here.func1 + a = Mock_Module.func1 a + c"; test.data.code = code.to_owned(); diff --git a/app/gui/src/controller/searcher.rs b/app/gui/src/controller/searcher.rs index 5f0a004a699a..09f13350b739 100644 --- a/app/gui/src/controller/searcher.rs +++ b/app/gui/src/controller/searcher.rs @@ -1954,7 +1954,6 @@ pub mod test { data.expect_completion(client, None, Some("String"), &[1]); data.expect_completion(client, None, Some("Number"), &[]); data.expect_completion(client, None, Some("Number"), &[]); - data.expect_completion(client, None, Some("Number"), &[]); data.expect_completion(client, None, None, &[1, 2, 3, 4, 9]); }); let Fixture { searcher, .. } = &mut fixture; From cdf61661e7e016bb8be90cc406914017d08dad65 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Sep 2022 20:51:54 +0300 Subject: [PATCH 9/9] fix: the rest of wasm tests --- app/gui/controller/double-representation/src/module.rs | 7 ++----- app/gui/src/controller/project.rs | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/gui/controller/double-representation/src/module.rs b/app/gui/controller/double-representation/src/module.rs index a97c6e8ee873..1e3006555f3e 100644 --- a/app/gui/controller/double-representation/src/module.rs +++ b/app/gui/controller/double-representation/src/module.rs @@ -793,11 +793,8 @@ pub fn lookup_method( let child_name = &child.name.item; let name_matches = child_name.name.item == method.name; let type_matches = match child_name.extended_target.as_slice() { - [] => implicit_extension_allowed, - [typename] => { - let explicit_type_matching = typename.item == qualified_typename.name; - explicit_type_matching || defined_in_this_module - } + [] => implicit_extension_allowed || defined_in_this_module, + [typename] => typename.item == qualified_typename.name, _ => child_name.explicitly_extends_type(&method.defined_on_type), }; if name_matches && type_matches { diff --git a/app/gui/src/controller/project.rs b/app/gui/src/controller/project.rs index 36716a579981..d337af05ebdb 100644 --- a/app/gui/src/controller/project.rs +++ b/app/gui/src/controller/project.rs @@ -302,7 +302,6 @@ mod tests { assert_eq!(code, module.ast().repr()); }; expect_intact("main = 5"); - expect_intact("here.main = 5"); expect_intact(&format!("{}.main = 5", module_name)); } }