Skip to content

Commit

Permalink
Fix multiline pattern idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
reese authored Jan 8, 2024
1 parent 4bc03e3 commit e12573c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions librubyfmt/rubyfmt_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ def on_var_field(ident)
super + start_end
end

def on_aryptn(*_)
with_lineno { super }
end

def on_fndptn(*_)
with_lineno { super }
end

def on_tlambda(*args)
@tlambda_stack << lineno
super
Expand Down
14 changes: 11 additions & 3 deletions librubyfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3408,8 +3408,14 @@ fn format_pattern(ps: &mut dyn ConcreteParserState, pattern_node: PatternNode) {

fn format_aryptn(ps: &mut dyn ConcreteParserState, aryptn: Aryptn) {
// Making this `mut` for
let Aryptn(_, maybe_collection_name, maybe_pre_star_list, maybe_star, maybe_post_star_list) =
aryptn;
let Aryptn(
_,
maybe_collection_name,
maybe_pre_star_list,
maybe_star,
maybe_post_star_list,
start_end,
) = aryptn;
if let Some(collection_name) = maybe_collection_name {
format_var_ref(ps, collection_name);
}
Expand Down Expand Up @@ -3441,10 +3447,11 @@ fn format_aryptn(ps: &mut dyn ConcreteParserState, aryptn: Aryptn) {
}),
);
}));
ps.wind_dumping_comments_until_line(start_end.end_line());
}

fn format_fndptn(ps: &mut dyn ConcreteParserState, fndptn: Fndptn) {
let Fndptn(_, maybe_collection_name, pre_splat, values, post_splat) = fndptn;
let Fndptn(_, maybe_collection_name, pre_splat, values, post_splat, start_end) = fndptn;
if let Some(collection_name) = maybe_collection_name {
format_var_ref(ps, collection_name);
}
Expand All @@ -3463,6 +3470,7 @@ fn format_fndptn(ps: &mut dyn ConcreteParserState, fndptn: Fndptn) {
}),
);
}));
ps.wind_dumping_comments_until_line(start_end.end_line());
}

fn pattern_splat_as_expr(var_field: VarField) -> Expression {
Expand Down
2 changes: 2 additions & 0 deletions librubyfmt/src/ripper_tree_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,7 @@ pub struct Aryptn(
pub Option<Vec<ExpressionOrVarField>>, // list of values before the first *
pub Option<VarField>, // "*" pattern
pub Option<Vec<ExpressionOrVarField>>, // list of values the first *
pub StartEnd,
);

def_tag!(fndptn_tag, "fndptn");
Expand All @@ -2446,6 +2447,7 @@ pub struct Fndptn(
pub VarField, // leading "*" pattern
pub Vec<ExpressionOrVarField>, // inner values
pub VarField, // trailing "*" pattern
pub StartEnd,
);

#[derive(RipperDeserialize, Debug, Clone)]
Expand Down

0 comments on commit e12573c

Please sign in to comment.