feat: update formatter for new changes
This commit is contained in:
parent
a4f6388eca
commit
6dc4738b66
|
@ -377,12 +377,9 @@ impl<'comments> Formatter<'comments> {
|
||||||
..
|
..
|
||||||
} => docvec![module, ".", name],
|
} => docvec![module, ".", name],
|
||||||
|
|
||||||
Constant::Tuple { elements, .. } => "#"
|
Constant::Tuple { elements, .. } => {
|
||||||
.to_doc()
|
wrap_args(elements.iter().map(|e| (self.const_expr(e), false))).group()
|
||||||
.append(wrap_args(
|
}
|
||||||
elements.iter().map(|e| (self.const_expr(e), false)),
|
|
||||||
))
|
|
||||||
.group(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +421,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_ast_constructor<'a>(
|
fn type_annotation_constructor<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &'a Option<String>,
|
module: &'a Option<String>,
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
|
@ -451,7 +448,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
arguments: args,
|
arguments: args,
|
||||||
module,
|
module,
|
||||||
..
|
..
|
||||||
} => self.type_ast_constructor(module, name, args),
|
} => self.type_annotation_constructor(module, name, args),
|
||||||
|
|
||||||
Annotation::Fn {
|
Annotation::Fn {
|
||||||
arguments: args,
|
arguments: args,
|
||||||
|
@ -459,19 +456,21 @@ impl<'comments> Formatter<'comments> {
|
||||||
..
|
..
|
||||||
} => "fn"
|
} => "fn"
|
||||||
.to_doc()
|
.to_doc()
|
||||||
.append(self.type_arguments(args))
|
.append(wrap_args(args.iter().map(|t| (self.annotation(t), false))))
|
||||||
.group()
|
.group()
|
||||||
.append(" ->")
|
.append(" ->")
|
||||||
.append(break_("", " ").append(self.annotation(retrn)).nest(INDENT)),
|
.append(break_("", " ").append(self.annotation(retrn)).nest(INDENT)),
|
||||||
|
|
||||||
Annotation::Var { name, .. } => name.to_doc(),
|
Annotation::Var { name, .. } => name.to_doc(),
|
||||||
Annotation::Tuple { elems, .. } => "#".to_doc().append(self.type_arguments(elems)),
|
Annotation::Tuple { elems, .. } => {
|
||||||
|
wrap_args(elems.iter().map(|t| (self.annotation(t), false)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.group()
|
.group()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_arguments<'a>(&mut self, args: &'a [Annotation]) -> Document<'a> {
|
fn type_arguments<'a>(&mut self, args: &'a [Annotation]) -> Document<'a> {
|
||||||
wrap_args(args.iter().map(|t| (self.annotation(t), false)))
|
wrap_generics(args.iter().map(|t| self.annotation(t)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_alias<'a>(
|
pub fn type_alias<'a>(
|
||||||
|
@ -486,7 +485,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
let head = if args.is_empty() {
|
let head = if args.is_empty() {
|
||||||
head
|
head
|
||||||
} else {
|
} else {
|
||||||
head.append(wrap_args(args.iter().map(|e| (e.to_doc(), false))).group())
|
head.append(wrap_generics(args.iter().map(|e| e.to_doc())).group())
|
||||||
};
|
};
|
||||||
|
|
||||||
head.append(" =")
|
head.append(" =")
|
||||||
|
@ -784,10 +783,9 @@ impl<'comments> Formatter<'comments> {
|
||||||
..
|
..
|
||||||
} => self.record_update(constructor, spread, args),
|
} => self.record_update(constructor, spread, args),
|
||||||
|
|
||||||
UntypedExpr::Tuple { elems, .. } => "#"
|
UntypedExpr::Tuple { elems, .. } => {
|
||||||
.to_doc()
|
wrap_args(elems.iter().map(|e| (self.wrap_expr(e), false))).group()
|
||||||
.append(wrap_args(elems.iter().map(|e| (self.wrap_expr(e), false))))
|
}
|
||||||
.group(),
|
|
||||||
};
|
};
|
||||||
commented(document, comments)
|
commented(document, comments)
|
||||||
}
|
}
|
||||||
|
@ -1146,7 +1144,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
name.to_doc()
|
name.to_doc()
|
||||||
} else {
|
} else {
|
||||||
name.to_doc()
|
name.to_doc()
|
||||||
.append(wrap_args(args.iter().map(|e| (e.to_doc(), false))))
|
.append(wrap_generics(args.iter().map(|e| e.to_doc())))
|
||||||
.group()
|
.group()
|
||||||
})
|
})
|
||||||
.append(" {")
|
.append(" {")
|
||||||
|
@ -1351,10 +1349,9 @@ impl<'comments> Formatter<'comments> {
|
||||||
|
|
||||||
Pattern::Discard { name, .. } => name.to_doc(),
|
Pattern::Discard { name, .. } => name.to_doc(),
|
||||||
|
|
||||||
Pattern::Tuple { elems, .. } => "#"
|
Pattern::Tuple { elems, .. } => {
|
||||||
.to_doc()
|
wrap_args(elems.iter().map(|e| (self.pattern(e), false))).group()
|
||||||
.append(wrap_args(elems.iter().map(|e| (self.pattern(e), false))))
|
}
|
||||||
.group(),
|
|
||||||
|
|
||||||
Pattern::List { elements, tail, .. } => {
|
Pattern::List { elements, tail, .. } => {
|
||||||
let elements_document =
|
let elements_document =
|
||||||
|
@ -1536,6 +1533,17 @@ where
|
||||||
.append(close)
|
.append(close)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn wrap_generics<'a, I>(args: I) -> Document<'a>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = Document<'a>>,
|
||||||
|
{
|
||||||
|
break_("<", "<")
|
||||||
|
.append(join(args, break_(",", ", ")))
|
||||||
|
.nest(INDENT)
|
||||||
|
.append(break_(",", ""))
|
||||||
|
.append(">")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn wrap_fields<'a, I>(args: I) -> Document<'a>
|
pub fn wrap_fields<'a, I>(args: I) -> Document<'a>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = Document<'a>>,
|
I: IntoIterator<Item = Document<'a>>,
|
||||||
|
|
|
@ -2,13 +2,9 @@ use sample
|
||||||
|
|
||||||
pub fn spend(datum: sample.Datum, rdmr: sample.Redeemer, _ctx: Nil) -> Bool {
|
pub fn spend(datum: sample.Datum, rdmr: sample.Redeemer, _ctx: Nil) -> Bool {
|
||||||
let x = (datum, rdmr, #[244])
|
let x = (datum, rdmr, #[244])
|
||||||
|
|
||||||
let y = [(#[222], #[222]), (#[233], #[52])]
|
let y = [(#[222], #[222]), (#[233], #[52])]
|
||||||
|
|
||||||
let [z, f, ..g] = y
|
let [z, f, ..g] = y
|
||||||
|
|
||||||
let (a, b, _) = x
|
let (a, b, _) = x
|
||||||
|
|
||||||
z == (#[222], #[222])
|
z == (#[222], #[222])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue