mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-01 21:40:58 +00:00
Fix a couple issues with multiline string literal formatting
This commit is contained in:
parent
316ec39af7
commit
962534e3d1
5 changed files with 76 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::annotation::{except_last, is_collection_multiline, Formattable, Newlines, Parens};
|
||||
use crate::collection::{fmt_collection, Braces};
|
||||
use crate::def::{fmt_defs, valdef_lift_spaces_before};
|
||||
use crate::def::{fmt_defs, valdef_lift_spaces_before, starts_with_block_string_literal};
|
||||
use crate::node::Prec;
|
||||
use crate::pattern::{
|
||||
fmt_pattern, pattern_lift_spaces, snakify_camel_ident, starts_with_inline_comment,
|
||||
|
|
@ -264,7 +264,7 @@ fn format_expr_only(
|
|||
let before_all_newlines = lifted.before.iter().all(|s| s.is_newline());
|
||||
|
||||
let needs_newline =
|
||||
!before_all_newlines || term_starts_with_multiline_str(&lifted.item);
|
||||
!before_all_newlines || starts_with_block_string_literal(&lifted.item);
|
||||
|
||||
let needs_parens = (needs_newline
|
||||
&& matches!(unary_op.value, called_via::UnaryOp::Negate))
|
||||
|
|
@ -367,14 +367,6 @@ fn format_expr_only(
|
|||
}
|
||||
}
|
||||
|
||||
fn term_starts_with_multiline_str(expr: &Expr<'_>) -> bool {
|
||||
match expr {
|
||||
Expr::Str(text) => is_str_multiline(text),
|
||||
Expr::PncApply(inner, _) => term_starts_with_multiline_str(&inner.value),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_expr_field_collection<'a>(
|
||||
arena: &'a Bump,
|
||||
items: Collection<'a, Loc<AssignedField<'a, Expr<'a>>>>,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
(
|
||||
(
|
||||
d
|
||||
-(
|
||||
"""
|
||||
"""()?
|
||||
)
|
||||
)
|
||||
)
|
||||
Y
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
@0-17 SpaceAfter(
|
||||
Apply(
|
||||
@1-15 ParensAround(
|
||||
ParensAround(
|
||||
Defs(
|
||||
Defs {
|
||||
tags: [
|
||||
EitherIndex(2147483648),
|
||||
],
|
||||
regions: [
|
||||
@2-3,
|
||||
],
|
||||
space_before: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
space_after: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
spaces: [],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
Stmt(
|
||||
@2-3 Var {
|
||||
module_name: "",
|
||||
ident: "d",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
@4-14 SpaceBefore(
|
||||
UnaryOp(
|
||||
@5-13 TrySuffix(
|
||||
PncApply(
|
||||
@5-11 Str(
|
||||
Block(
|
||||
[],
|
||||
),
|
||||
),
|
||||
[],
|
||||
),
|
||||
),
|
||||
@4-5 Negate,
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
[
|
||||
@16-17 Tag(
|
||||
"Y",
|
||||
),
|
||||
],
|
||||
Space,
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
((d
|
||||
-""""""()?))Y
|
||||
|
|
@ -403,6 +403,7 @@ mod test_snapshots {
|
|||
pass/crazy_annotation_left.expr,
|
||||
pass/crazy_annotation_left2.expr,
|
||||
pass/crazy_implements_bangs.expr,
|
||||
pass/crazy_parens_multiline_str_question_etc.expr,
|
||||
pass/crazy_pat_ann.expr,
|
||||
pass/curried_function_type.expr,
|
||||
pass/dbg.expr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue