mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
keep indent state in fmt Buf
This commit is contained in:
parent
e872d00b13
commit
e3f2f8d9a4
11 changed files with 313 additions and 182 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::annotation::{Formattable, Newlines, Parens};
|
||||
use crate::pattern::fmt_pattern;
|
||||
use crate::spaces::{fmt_spaces, newline, INDENT};
|
||||
use bumpalo::collections::String;
|
||||
use crate::spaces::{fmt_spaces, INDENT};
|
||||
use crate::Buf;
|
||||
use roc_parse::ast::{Def, Expr, Pattern};
|
||||
use roc_region::all::Located;
|
||||
|
||||
|
@ -27,7 +27,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
|
||||
fn format_with_options(
|
||||
&self,
|
||||
buf: &mut String<'a>,
|
||||
buf: &mut Buf<'a>,
|
||||
_parens: Parens,
|
||||
_newlines: Newlines,
|
||||
indent: u16,
|
||||
|
@ -43,7 +43,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
buf,
|
||||
Parens::NotNeeded,
|
||||
Newlines::Yes,
|
||||
indent,
|
||||
indent + INDENT,
|
||||
);
|
||||
} else {
|
||||
buf.push_str(" : ");
|
||||
|
@ -56,6 +56,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
}
|
||||
}
|
||||
Alias { name, vars, ann } => {
|
||||
buf.indent(indent);
|
||||
buf.push_str(name.value);
|
||||
|
||||
if vars.is_empty() {
|
||||
|
@ -69,7 +70,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
|
||||
buf.push_str(" : ");
|
||||
|
||||
ann.format(buf, indent)
|
||||
ann.format(buf, indent + INDENT)
|
||||
}
|
||||
Body(loc_pattern, loc_expr) => {
|
||||
fmt_body(buf, &loc_pattern.value, &loc_expr.value, indent);
|
||||
|
@ -89,7 +90,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
buf.push_str(" # ");
|
||||
buf.push_str(comment_str.trim());
|
||||
}
|
||||
newline(buf, indent);
|
||||
buf.newline();
|
||||
fmt_body(buf, &body_pattern.value, &body_expr.value, indent);
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,7 @@ impl<'a> Formattable<'a> for Def<'a> {
|
|||
}
|
||||
|
||||
fn fmt_expect<'a>(
|
||||
buf: &mut String<'a>,
|
||||
buf: &mut Buf<'a>,
|
||||
condition: &'a Located<Expr<'a>>,
|
||||
is_multiline: bool,
|
||||
indent: u16,
|
||||
|
@ -122,16 +123,11 @@ fn fmt_expect<'a>(
|
|||
condition.format(buf, return_indent);
|
||||
}
|
||||
|
||||
pub fn fmt_def<'a>(buf: &mut String<'a>, def: &Def<'a>, indent: u16) {
|
||||
pub fn fmt_def<'a>(buf: &mut Buf<'a>, def: &Def<'a>, indent: u16) {
|
||||
def.format(buf, indent);
|
||||
}
|
||||
|
||||
pub fn fmt_body<'a>(
|
||||
buf: &mut String<'a>,
|
||||
pattern: &'a Pattern<'a>,
|
||||
body: &'a Expr<'a>,
|
||||
indent: u16,
|
||||
) {
|
||||
pub fn fmt_body<'a>(buf: &mut Buf<'a>, pattern: &'a Pattern<'a>, body: &'a Expr<'a>, indent: u16) {
|
||||
pattern.format_with_options(buf, Parens::InApply, Newlines::No, indent);
|
||||
buf.push_str(" =");
|
||||
if body.is_multiline() {
|
||||
|
@ -140,7 +136,7 @@ pub fn fmt_body<'a>(
|
|||
body.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent + INDENT);
|
||||
}
|
||||
Expr::Record { .. } | Expr::List { .. } => {
|
||||
newline(buf, indent + INDENT);
|
||||
buf.newline();
|
||||
body.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent + INDENT);
|
||||
}
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue