mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Fix module formatting
This commit is contained in:
parent
271112fec1
commit
34e9b1b73d
6 changed files with 42 additions and 38 deletions
|
@ -16,8 +16,6 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
|
||||||
) where
|
) where
|
||||||
<T as ExtractSpaces<'a>>::Item: Formattable,
|
<T as ExtractSpaces<'a>>::Item: Formattable,
|
||||||
{
|
{
|
||||||
buf.indent(indent);
|
|
||||||
|
|
||||||
if items.is_multiline() {
|
if items.is_multiline() {
|
||||||
let braces_indent = indent;
|
let braces_indent = indent;
|
||||||
let item_indent = braces_indent + INDENT;
|
let item_indent = braces_indent + INDENT;
|
||||||
|
@ -50,9 +48,12 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
|
||||||
item_indent,
|
item_indent,
|
||||||
);
|
);
|
||||||
buf.newline();
|
buf.newline();
|
||||||
|
buf.indent(braces_indent);
|
||||||
|
buf.push(end);
|
||||||
} else {
|
} else {
|
||||||
// is_multiline == false
|
// is_multiline == false
|
||||||
// there is no comment to add
|
// there is no comment to add
|
||||||
|
buf.indent(indent);
|
||||||
buf.push(start);
|
buf.push(start);
|
||||||
let mut iter = items.iter().peekable();
|
let mut iter = items.iter().peekable();
|
||||||
while let Some(item) = iter.next() {
|
while let Some(item) = iter.next() {
|
||||||
|
@ -66,7 +67,7 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
|
||||||
if !items.is_empty() {
|
if !items.is_empty() {
|
||||||
buf.spaces(1);
|
buf.spaces(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
buf.indent(indent);
|
|
||||||
buf.push(end);
|
buf.push(end);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,14 @@ fn fmt_effects<'a, 'buf>(buf: &mut Buf<'buf>, effects: &Effects<'a>, indent: u16
|
||||||
|
|
||||||
fmt_default_spaces(buf, effects.spaces_after_type_name, indent);
|
fmt_default_spaces(buf, effects.spaces_after_type_name, indent);
|
||||||
|
|
||||||
fmt_collection(buf, indent, '{', '}', effects.entries, Newlines::No)
|
fmt_collection(
|
||||||
|
buf,
|
||||||
|
indent + INDENT,
|
||||||
|
'{',
|
||||||
|
'}',
|
||||||
|
effects.entries,
|
||||||
|
Newlines::No,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Formattable for TypedIdent<'a> {
|
impl<'a> Formattable for TypedIdent<'a> {
|
||||||
|
@ -260,7 +267,7 @@ fn fmt_imports<'a, 'buf>(
|
||||||
loc_entries: Collection<'a, Loc<Spaced<'a, ImportsEntry<'a>>>>,
|
loc_entries: Collection<'a, Loc<Spaced<'a, ImportsEntry<'a>>>>,
|
||||||
indent: u16,
|
indent: u16,
|
||||||
) {
|
) {
|
||||||
fmt_collection(buf, indent, '[', ']', loc_entries, Newlines::No)
|
fmt_collection(buf, indent + INDENT, '[', ']', loc_entries, Newlines::No)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_provides<'a, 'buf>(
|
fn fmt_provides<'a, 'buf>(
|
||||||
|
@ -270,9 +277,9 @@ fn fmt_provides<'a, 'buf>(
|
||||||
indent: u16,
|
indent: u16,
|
||||||
) {
|
) {
|
||||||
fmt_collection(buf, indent, '[', ']', loc_exposed_names, Newlines::No);
|
fmt_collection(buf, indent, '[', ']', loc_exposed_names, Newlines::No);
|
||||||
if let Some(loc_provided_types) = loc_provided_types {
|
if let Some(loc_provided) = loc_provided_types {
|
||||||
fmt_default_spaces(buf, &[], indent);
|
fmt_default_spaces(buf, &[], indent);
|
||||||
fmt_collection(buf, indent, '{', '}', loc_provided_types, Newlines::No);
|
fmt_collection(buf, indent + INDENT, '{', '}', loc_provided, Newlines::No);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +297,7 @@ fn fmt_exposes<'buf, N: Formattable + Copy>(
|
||||||
loc_entries: Collection<'_, Loc<Spaced<'_, N>>>,
|
loc_entries: Collection<'_, Loc<Spaced<'_, N>>>,
|
||||||
indent: u16,
|
indent: u16,
|
||||||
) {
|
) {
|
||||||
fmt_collection(buf, indent, '[', ']', loc_entries, Newlines::No)
|
fmt_collection(buf, indent + INDENT, '[', ']', loc_entries, Newlines::No)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FormatName {
|
pub trait FormatName {
|
||||||
|
|
|
@ -8,7 +8,7 @@ platform "folkertdev/foo"
|
||||||
{
|
{
|
||||||
putLine : Str -> Effect {},
|
putLine : Str -> Effect {},
|
||||||
putInt : I64 -> Effect {},
|
putInt : I64 -> Effect {},
|
||||||
getInt : Effect { value : I64, errorCode : [ A, B ], isError : Bool }
|
getInt : Effect { value : I64, errorCode : [ A, B ], isError : Bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
mainForHost : Task {} [] as Fx
|
mainForHost : Task {} [] as Fx
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
platform "examples/cli"
|
platform "examples/cli"
|
||||||
requires {} { main : Task {} [] }# TODO FIXME
|
requires {} { main : Task {} [] }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports [ Task.{ Task } ]
|
imports [ Task.{ Task } ]
|
||||||
provides [ mainForHost ]
|
provides [ mainForHost ]
|
||||||
effects fx.Effect
|
effects fx.Effect { putLine : Str -> Effect {}, getLine : Effect Str }
|
||||||
{
|
|
||||||
putLine : Str -> Effect {},
|
|
||||||
getLine : Effect Str
|
|
||||||
}
|
|
||||||
|
|
||||||
mainForHost : Task {} [] as Fx
|
mainForHost : Task {} [] as Fx
|
||||||
mainForHost = main
|
mainForHost = main
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
platform "folkertdev/foo"
|
platform "roc-examples/cli"
|
||||||
requires {} { main : Effect {} }
|
requires {} { main : Effect {} }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
|
@ -7,7 +7,7 @@ platform "folkertdev/foo"
|
||||||
effects fx.Effect
|
effects fx.Effect
|
||||||
{
|
{
|
||||||
putLine : Str -> Effect {},
|
putLine : Str -> Effect {},
|
||||||
getLine : Effect Str
|
getLine : Effect Str,
|
||||||
}
|
}
|
||||||
|
|
||||||
mainForHost : Effect.Effect {} as Fx
|
mainForHost : Effect.Effect {} as Fx
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform "examples/cli"
|
platform "examples/cli"
|
||||||
requires {} { main : Str -> Task {} [] }# TODO FIXME
|
requires {} { main : Str -> Task {} [] }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports [ Task.{ Task } ]
|
imports [ Task.{ Task } ]
|
||||||
|
@ -15,7 +15,7 @@ platform "examples/cli"
|
||||||
putRaw : Str -> Effect {},
|
putRaw : Str -> Effect {},
|
||||||
# Is there a limit to the number of effect, uncomment the next line and it crashes
|
# Is there a limit to the number of effect, uncomment the next line and it crashes
|
||||||
# getLine : Effect Str,
|
# getLine : Effect Str,
|
||||||
getChar : Effect U8
|
getChar : Effect U8,
|
||||||
}
|
}
|
||||||
|
|
||||||
mainForHost : Str -> Task {} [] as Fx
|
mainForHost : Str -> Task {} [] as Fx
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue