From 34e9b1b73d28d6590bf68bd6517edeecaab32921 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 1 Feb 2022 21:20:14 -0500 Subject: [PATCH] Fix module formatting --- compiler/fmt/src/collection.rs | 9 ++++--- compiler/fmt/src/module.rs | 17 ++++++++---- .../benchmarks/platform/Package-Config.roc | 10 +++---- examples/cli/platform/Package-Config.roc | 8 ++---- .../thing/platform-dir/Package-Config.roc | 10 +++---- .../platform/Package-Config.roc | 26 +++++++++---------- 6 files changed, 42 insertions(+), 38 deletions(-) diff --git a/compiler/fmt/src/collection.rs b/compiler/fmt/src/collection.rs index 9b31bad527..5765f0f4d1 100644 --- a/compiler/fmt/src/collection.rs +++ b/compiler/fmt/src/collection.rs @@ -16,8 +16,6 @@ pub fn fmt_collection<'a, 'buf, T: ExtractSpaces<'a> + Formattable>( ) where >::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); } diff --git a/compiler/fmt/src/module.rs b/compiler/fmt/src/module.rs index c25b67427d..669edc61af 100644 --- a/compiler/fmt/src/module.rs +++ b/compiler/fmt/src/module.rs @@ -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>>>, 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>>, indent: u16, ) { - fmt_collection(buf, indent, '[', ']', loc_entries, Newlines::No) + fmt_collection(buf, indent + INDENT, '[', ']', loc_entries, Newlines::No) } pub trait FormatName { diff --git a/examples/benchmarks/platform/Package-Config.roc b/examples/benchmarks/platform/Package-Config.roc index 619534f070..07583550da 100644 --- a/examples/benchmarks/platform/Package-Config.roc +++ b/examples/benchmarks/platform/Package-Config.roc @@ -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 diff --git a/examples/cli/platform/Package-Config.roc b/examples/cli/platform/Package-Config.roc index 93a045a908..f82a01c43b 100644 --- a/examples/cli/platform/Package-Config.roc +++ b/examples/cli/platform/Package-Config.roc @@ -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 diff --git a/examples/effect/thing/platform-dir/Package-Config.roc b/examples/effect/thing/platform-dir/Package-Config.roc index 667e960a28..17d8a92f5d 100644 --- a/examples/effect/thing/platform-dir/Package-Config.roc +++ b/examples/effect/thing/platform-dir/Package-Config.roc @@ -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 diff --git a/examples/false-interpreter/platform/Package-Config.roc b/examples/false-interpreter/platform/Package-Config.roc index 55003feeea..da5868f3b3 100644 --- a/examples/false-interpreter/platform/Package-Config.roc +++ b/examples/false-interpreter/platform/Package-Config.roc @@ -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