Merge branch 'trunk' into fix-module-formatting

This commit is contained in:
Richard Feldman 2022-02-04 23:03:52 -05:00 committed by GitHub
commit 881bae7267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
114 changed files with 4260 additions and 1986 deletions

View file

@ -46,7 +46,9 @@ impl<'a> Formattable for Def<'a> {
indent + INDENT,
);
} else {
buf.push_str(" : ");
buf.spaces(1);
buf.push_str(":");
buf.spaces(1);
loc_annotation.format_with_options(
buf,
Parens::NotNeeded,

View file

@ -27,8 +27,8 @@ impl<'a> Formattable for Expr<'a> {
}
// These expressions never have newlines
Float(_)
| Num(_)
Float(..)
| Num(..)
| NonBase10Int { .. }
| Access(_, _)
| AccessorFunction(_)
@ -196,17 +196,25 @@ impl<'a> Formattable for Expr<'a> {
buf.push(')');
}
}
Num(string) | Float(string) | GlobalTag(string) | PrivateTag(string) => {
&Num(string) => {
buf.indent(indent);
buf.push_str(string);
}
&Float(string) => {
buf.indent(indent);
buf.push_str(string);
}
GlobalTag(string) | PrivateTag(string) => {
buf.indent(indent);
buf.push_str(string)
}
NonBase10Int {
&NonBase10Int {
base,
string,
is_negative,
} => {
buf.indent(indent);
if *is_negative {
if is_negative {
buf.push('-');
}

View file

@ -5,8 +5,8 @@ use crate::spaces::{fmt_default_spaces, fmt_spaces, INDENT};
use crate::Buf;
use roc_parse::ast::{Collection, Module, Spaced};
use roc_parse::header::{
AppHeader, Effects, ExposedName, HostedHeader, ImportsEntry, InterfaceHeader, ModuleName,
PackageEntry, PackageName, PlatformHeader, PlatformRequires, To, TypedIdent,
AppHeader, ExposedName, HostedHeader, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
PackageName, PlatformHeader, PlatformRequires, To, TypedIdent,
};
use roc_parse::ident::UppercaseIdent;
use roc_region::all::Loc;
@ -170,8 +170,6 @@ pub fn fmt_platform_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a PlatformHe
buf.push_str("provides");
fmt_default_spaces(buf, header.after_provides, indent);
fmt_provides(buf, header.provides, None, indent);
fmt_effects(buf, &header.effects, indent);
}
fn fmt_requires<'a, 'buf>(buf: &mut Buf<'buf>, requires: &PlatformRequires<'a>, indent: u16) {
@ -183,29 +181,6 @@ fn fmt_requires<'a, 'buf>(buf: &mut Buf<'buf>, requires: &PlatformRequires<'a>,
buf.push_str(" }");
}
fn fmt_effects<'a, 'buf>(buf: &mut Buf<'buf>, effects: &Effects<'a>, indent: u16) {
fmt_default_spaces(buf, effects.spaces_before_effects_keyword, indent);
buf.indent(indent);
buf.push_str("effects");
fmt_default_spaces(buf, effects.spaces_after_effects_keyword, indent);
buf.indent(indent);
buf.push_str(effects.effect_shortname);
buf.push('.');
buf.push_str(effects.effect_type_name);
fmt_default_spaces(buf, effects.spaces_after_type_name, indent);
fmt_collection(
buf,
indent + INDENT,
'{',
'}',
effects.entries,
Newlines::No,
)
}
impl<'a> Formattable for TypedIdent<'a> {
fn is_multiline(&self) -> bool {
false

View file

@ -31,9 +31,9 @@ impl<'a> Formattable for Pattern<'a> {
| Pattern::GlobalTag(_)
| Pattern::PrivateTag(_)
| Pattern::Apply(_, _)
| Pattern::NumLiteral(_)
| Pattern::NumLiteral(..)
| Pattern::NonBase10Literal { .. }
| Pattern::FloatLiteral(_)
| Pattern::FloatLiteral(..)
| Pattern::StrLiteral(_)
| Pattern::Underscore(_)
| Pattern::Malformed(_)
@ -116,17 +116,17 @@ impl<'a> Formattable for Pattern<'a> {
loc_pattern.format(buf, indent);
}
NumLiteral(string) => {
&NumLiteral(string) => {
buf.indent(indent);
buf.push_str(string);
}
NonBase10Literal {
&NonBase10Literal {
base,
string,
is_negative,
} => {
buf.indent(indent);
if *is_negative {
if is_negative {
buf.push('-');
}
@ -139,7 +139,7 @@ impl<'a> Formattable for Pattern<'a> {
buf.push_str(string);
}
FloatLiteral(string) => {
&FloatLiteral(string) => {
buf.indent(indent);
buf.push_str(string);
}