Skip to content

Commit

Permalink
Fix precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
reese authored Aug 18, 2023
1 parent 9a39f02 commit 087a994
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
30 changes: 15 additions & 15 deletions librubyfmt/src/render_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,21 @@ impl AbstractTokenTarget for BreakableCallChainEntry {
}
}

let all_element_locations = call_chain_to_check
.iter()
.filter_map(|cc_elem| cc_elem.start_line())
.collect::<Vec<u64>>();

// Multiline the chain if all the call chain elements are not on the same line
if let Some(first_op_start_end) = all_element_locations.first() {
let chain_is_user_multilined = !all_element_locations
.iter()
.all(|op_start_end| op_start_end == first_op_start_end);
if chain_is_user_multilined {
return true;
}
}

// Ignore chains that are basically only method calls, e.g.
// ````ruby
// Thing.foo(args)
Expand All @@ -363,21 +378,6 @@ impl AbstractTokenTarget for BreakableCallChainEntry {
_ => {}
}

let all_element_locations = call_chain_to_check
.iter()
.filter_map(|cc_elem| cc_elem.start_line())
.collect::<Vec<u64>>();

// Multiline the chain if all the call chain elements are not on the same line
if let Some(first_op_start_end) = all_element_locations.first() {
let chain_is_user_multilined = !all_element_locations
.iter()
.all(|op_start_end| op_start_end == first_op_start_end);
if chain_is_user_multilined {
return true;
}
}

let chain_blocks_are_multilined = call_chain_to_check
.iter()
.filter_map(|elem| match elem {
Expand Down
11 changes: 4 additions & 7 deletions librubyfmt/src/ripper_tree_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,13 +1608,10 @@ impl CallChainElement {
}
CallChainElement::Block(block) => Some(block.start_line()),
CallChainElement::VarRef(VarRef(.., var_ref_type)) => Some(var_ref_type.start_line()),
CallChainElement::ArgsAddStarOrExpressionListOrArgsForward(aas, maybe_start_end) => {
// The parser generally incorrectly reports the start_end for these, due to the fact that
// they sometimes don't have delimiters, so their begin/end will be overreported
if aas.is_empty() {
return None;
}
maybe_start_end.as_ref().map(|se| se.start_line())
CallChainElement::ArgsAddStarOrExpressionListOrArgsForward(..) => {
// The start_end for these is generally incorrect, since the parser event
// only fires at the _end_ of the expression list
None
}
CallChainElement::DotTypeOrOp(d) => d.start_line(),
CallChainElement::Paren(ParenExpr(.., start_end)) => Some(start_end.start_line()),
Expand Down

0 comments on commit 087a994

Please sign in to comment.