Merge pull request #2239 from rtfeldman/joshuawarner32/pipeline-format-fail

Fix formatting of pipelined call exprs
This commit is contained in:
Richard Feldman 2021-12-20 15:46:23 -05:00 committed by GitHub
commit 3ffe5768e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View file

@ -1,5 +1,6 @@
use crate::ast::{
AssignedField, Collection, CommentOrNewline, Def, Expr, Pattern, Spaceable, TypeAnnotation,
AssignedField, Collection, CommentOrNewline, Def, Expr, ExtractSpaces, Pattern, Spaceable,
TypeAnnotation,
};
use crate::blankspace::{space0_after_e, space0_around_ee, space0_before_e, space0_e};
use crate::ident::{lowercase_ident, parse_ident, Ident};
@ -480,7 +481,7 @@ fn parse_expr_final<'a>(
fn to_call<'a>(
arena: &'a Bump,
arguments: Vec<'a, &'a Located<Expr<'a>>>,
mut arguments: Vec<'a, &'a Located<Expr<'a>>>,
loc_expr1: Located<Expr<'a>>,
) -> Located<Expr<'a>> {
if arguments.is_empty() {
@ -489,12 +490,35 @@ fn to_call<'a>(
let last = arguments.last().map(|x| x.region).unwrap_or_default();
let region = Region::span_across(&loc_expr1.region, &last);
let apply = Expr::Apply(
let spaces = if let Some(last) = arguments.last_mut() {
let spaces = last.value.extract_spaces();
if spaces.after.is_empty() {
&[]
} else {
let inner = if !spaces.before.is_empty() {
arena.alloc(spaces.item).before(spaces.before)
} else {
spaces.item
};
*last = arena.alloc(Located::at(last.region, inner));
spaces.after
}
} else {
&[]
};
let mut apply = Expr::Apply(
arena.alloc(loc_expr1),
arguments.into_bump_slice(),
CalledVia::Space,
);
if !spaces.is_empty() {
apply = arena.alloc(apply).after(spaces)
}
Located::at(region, apply)
}
}