mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-13 09:49:11 +03:00
Fix module formatting
This commit is contained in:
parent
271112fec1
commit
34e9b1b73d
@ -16,8 +16,6 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
|
||||
) where
|
||||
<T as ExtractSpaces<'a>>::Item: Formattable,
|
||||
{
|
||||
buf.indent(indent);
|
||||
|
||||
if items.is_multiline() {
|
||||
let 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,
|
||||
);
|
||||
buf.newline();
|
||||
buf.indent(braces_indent);
|
||||
buf.push(end);
|
||||
} else {
|
||||
// is_multiline == false
|
||||
// there is no comment to add
|
||||
buf.indent(indent);
|
||||
buf.push(start);
|
||||
let mut iter = items.iter().peekable();
|
||||
while let Some(item) = iter.next() {
|
||||
@ -66,7 +67,7 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>(
|
||||
if !items.is_empty() {
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
buf.push(end);
|
||||
}
|
||||
buf.indent(indent);
|
||||
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_collection(buf, indent, '{', '}', effects.entries, Newlines::No)
|
||||
fmt_collection(
|
||||
buf,
|
||||
indent + INDENT,
|
||||
'{',
|
||||
'}',
|
||||
effects.entries,
|
||||
Newlines::No,
|
||||
)
|
||||
}
|
||||
|
||||
impl<'a> Formattable for TypedIdent<'a> {
|
||||
@ -260,7 +267,7 @@ fn fmt_imports<'a, 'buf>(
|
||||
loc_entries: Collection<'a, Loc<Spaced<'a, ImportsEntry<'a>>>>,
|
||||
indent: u16,
|
||||
) {
|
||||
fmt_collection(buf, indent, '[', ']', loc_entries, Newlines::No)
|
||||
fmt_collection(buf, indent + INDENT, '[', ']', loc_entries, Newlines::No)
|
||||
}
|
||||
|
||||
fn fmt_provides<'a, 'buf>(
|
||||
@ -270,9 +277,9 @@ fn fmt_provides<'a, 'buf>(
|
||||
indent: u16,
|
||||
) {
|
||||
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_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>>>,
|
||||
indent: u16,
|
||||
) {
|
||||
fmt_collection(buf, indent, '[', ']', loc_entries, Newlines::No)
|
||||
fmt_collection(buf, indent + INDENT, '[', ']', loc_entries, Newlines::No)
|
||||
}
|
||||
|
||||
pub trait FormatName {
|
||||
|
@ -5,11 +5,11 @@ platform "folkertdev/foo"
|
||||
imports [ Task.{ Task } ]
|
||||
provides [ mainForHost ]
|
||||
effects fx.Effect
|
||||
{
|
||||
putLine : Str -> Effect {},
|
||||
putInt : I64 -> Effect {},
|
||||
getInt : Effect { value : I64, errorCode : [ A, B ], isError : Bool }
|
||||
}
|
||||
{
|
||||
putLine : Str -> Effect {},
|
||||
putInt : I64 -> Effect {},
|
||||
getInt : Effect { value : I64, errorCode : [ A, B ], isError : Bool },
|
||||
}
|
||||
|
||||
mainForHost : Task {} [] as Fx
|
||||
mainForHost = main
|
||||
|
@ -1,14 +1,10 @@
|
||||
platform "examples/cli"
|
||||
requires {} { main : Task {} [] }# TODO FIXME
|
||||
requires {} { main : Task {} [] }
|
||||
exposes []
|
||||
packages {}
|
||||
imports [ Task.{ Task } ]
|
||||
provides [ mainForHost ]
|
||||
effects fx.Effect
|
||||
{
|
||||
putLine : Str -> Effect {},
|
||||
getLine : Effect Str
|
||||
}
|
||||
effects fx.Effect { putLine : Str -> Effect {}, getLine : Effect Str }
|
||||
|
||||
mainForHost : Task {} [] as Fx
|
||||
mainForHost = main
|
||||
|
@ -1,14 +1,14 @@
|
||||
platform "folkertdev/foo"
|
||||
platform "roc-examples/cli"
|
||||
requires {} { main : Effect {} }
|
||||
exposes []
|
||||
packages {}
|
||||
imports [ fx.Effect ]
|
||||
provides [ mainForHost ]
|
||||
effects fx.Effect
|
||||
{
|
||||
putLine : Str -> Effect {},
|
||||
getLine : Effect Str
|
||||
}
|
||||
{
|
||||
putLine : Str -> Effect {},
|
||||
getLine : Effect Str,
|
||||
}
|
||||
|
||||
mainForHost : Effect.Effect {} as Fx
|
||||
mainForHost = main
|
||||
|
@ -1,22 +1,22 @@
|
||||
platform "examples/cli"
|
||||
requires {} { main : Str -> Task {} [] }# TODO FIXME
|
||||
requires {} { main : Str -> Task {} [] }
|
||||
exposes []
|
||||
packages {}
|
||||
imports [ Task.{ Task } ]
|
||||
provides [ mainForHost ]
|
||||
effects fx.Effect
|
||||
{
|
||||
openFile : Str -> Effect U64,
|
||||
closeFile : U64 -> Effect {},
|
||||
withFileOpen : Str, (U64 -> Effect (Result ok err)) -> Effect {},
|
||||
getFileLine : U64 -> Effect Str,
|
||||
getFileBytes : U64 -> Effect (List U8),
|
||||
putLine : Str -> Effect {},
|
||||
putRaw : Str -> Effect {},
|
||||
# Is there a limit to the number of effect, uncomment the next line and it crashes
|
||||
# getLine : Effect Str,
|
||||
getChar : Effect U8
|
||||
}
|
||||
{
|
||||
openFile : Str -> Effect U64,
|
||||
closeFile : U64 -> Effect {},
|
||||
withFileOpen : Str, (U64 -> Effect (Result ok err)) -> Effect {},
|
||||
getFileLine : U64 -> Effect Str,
|
||||
getFileBytes : U64 -> Effect (List U8),
|
||||
putLine : Str -> Effect {},
|
||||
putRaw : Str -> Effect {},
|
||||
# Is there a limit to the number of effect, uncomment the next line and it crashes
|
||||
# getLine : Effect Str,
|
||||
getChar : Effect U8,
|
||||
}
|
||||
|
||||
mainForHost : Str -> Task {} [] as Fx
|
||||
mainForHost = \file -> main file
|
||||
|
Loading…
Reference in New Issue
Block a user