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

Support widgets and placeholders in more complex expressions #5656

Merged
merged 15 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
- [Improved component browser entry filtering and sorting][5645]. The component
browser will now provide suggestions matching either the component's label or
the corresponding code.
- [Improved argument placeholder resolution in more complex expressions][5656].
It is now possible to drop node connections onto missing arguments of chained
and nested function calls.

#### EnsoGL (rendering engine)

Expand Down Expand Up @@ -480,6 +483,7 @@
[4072]: https://github.com/enso-org/enso/pull/4072
[5645]: https://github.com/enso-org/enso/pull/5645
[5646]: https://github.com/enso-org/enso/pull/5646
[5656]: https://github.com/enso-org/enso/pull/5656

#### Enso Compiler

Expand Down
12 changes: 11 additions & 1 deletion app/gui/language/ast/impl/src/opr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,19 @@ impl GeneralizedInfix {
infix_id: self.id,
};

let rest_offset = rest.operand.as_ref().map_or_default(|op| op.offset);

let target_subtree_infix = target.clone().and_then(|arg| {
let offset = arg.offset;
GeneralizedInfix::try_new(&arg.arg).map(|arg| ArgWithOffset { arg, offset })
GeneralizedInfix::try_new(&arg.arg).map(|arg| ArgWithOffset { arg, offset }).filter(
|target_infix| {
// For access operators, do not flatten them if there is a space before the dot.
// For example, `Foo . Bar . Baz` should not be flattened to `Foo.Bar.Baz`, as
// those should be treated as potential separate prefix expressions, allowing
// operator placeholders to be inserted.
rest_offset == 0 || target_infix.arg.name() != predefined::ACCESS
},
)
});
let mut target_subtree_flat = match target_subtree_infix {
Some(target_infix) if target_infix.arg.name() == self.name() =>
Expand Down
12 changes: 6 additions & 6 deletions app/gui/language/span-tree/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub fn main() {
let parens_cr1 = ast::crumbs::MatchCrumb::Segs { val: val.clone(), index: 0 };
let parens_cr = ast::crumbs::MatchCrumb::Segs { val, index: 0 };
let _input_span_tree = builder::TreeBuilder::<()>::new(36)
.add_child(0, 14, node::Kind::Chained, PrefixCrumb::Func)
.add_child(0, 9, node::Kind::operation(), PrefixCrumb::Func)
.add_child(0, 14, node::Kind::chained(), PrefixCrumb::Func)
.add_child(0, 9, node::Kind::Operation, PrefixCrumb::Func)
.set_ast_id(Uuid::new_v4())
.done()
.add_empty_child(10, InsertionPointType::BeforeTarget)
Expand All @@ -41,7 +41,7 @@ pub fn main() {
.set_ast_id(Uuid::new_v4())
.add_child(1, 19, node::Kind::argument(), parens_cr1)
.set_ast_id(Uuid::new_v4())
.add_child(0, 12, node::Kind::operation(), PrefixCrumb::Func)
.add_child(0, 12, node::Kind::Operation, PrefixCrumb::Func)
.set_ast_id(Uuid::new_v4())
.done()
.add_empty_child(13, InsertionPointType::BeforeTarget)
Expand All @@ -57,11 +57,11 @@ pub fn main() {
let input_span_tree2 = Node::<()>::new()
.new_child(|t| {
t.new_ast_id()
.kind(node::Kind::Chained)
.kind(node::Kind::chained())
.crumbs(PrefixCrumb::Func)
.new_child(|t| {
t.size(9.bytes())
.kind(node::Kind::operation())
.kind(node::Kind::Operation)
.crumbs(PrefixCrumb::Func)
.new_ast_id()
})
Expand All @@ -85,7 +85,7 @@ pub fn main() {
.crumbs(parens_cr)
.new_child(|t| {
t.size(12.bytes())
.kind(node::Kind::operation())
.kind(node::Kind::Operation)
.crumbs(PrefixCrumb::Func)
.new_ast_id()
})
Expand Down
4 changes: 2 additions & 2 deletions app/gui/language/span-tree/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ mod test {
// Consider Span Tree for `foo bar` where `foo` is a method known to take 3 parameters.
// We can try setting each of 3 arguments to `baz`.
let tree = TreeBuilder::<()>::new(7)
.add_leaf(0, 3, node::Kind::operation(), PrefixCrumb::Func)
.add_leaf(0, 3, node::Kind::Operation, PrefixCrumb::Func)
.add_leaf(4, 7, node::Kind::this(), PrefixCrumb::Arg)
.add_empty_child(7, ExpectedArgument(1))
.add_empty_child(7, ExpectedArgument(2))
Expand All @@ -416,7 +416,7 @@ mod test {
// parameters. We can try setting each of 2 arguments to `baz`.
let tree: SpanTree = TreeBuilder::new(10)
.add_leaf(0, 4, node::Kind::this(), InfixCrumb::LeftOperand)
.add_leaf(5, 6, node::Kind::operation(), InfixCrumb::Operator)
.add_leaf(5, 6, node::Kind::Operation, InfixCrumb::Operator)
.add_leaf(7, 10, node::Kind::argument(), InfixCrumb::RightOperand)
.add_empty_child(10, ExpectedArgument(0))
.add_empty_child(10, ExpectedArgument(1))
Expand Down
Loading