mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-13 07:16:18 +00:00
parent
d12568d8e4
commit
df3b7cb1b4
2 changed files with 41 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
use crate::annotation::{Formattable, Newlines};
|
use crate::annotation::{Formattable, Newlines};
|
||||||
use crate::collection::{fmt_collection, Braces};
|
use crate::collection::{fmt_collection, Braces};
|
||||||
use crate::expr::fmt_str_literal;
|
use crate::expr::fmt_str_literal;
|
||||||
use crate::spaces::{fmt_default_spaces, fmt_spaces, INDENT};
|
use crate::spaces::{fmt_comments_only, fmt_default_spaces, fmt_spaces, NewlineAt, INDENT};
|
||||||
use crate::Buf;
|
use crate::Buf;
|
||||||
use roc_parse::ast::{Collection, Module, Spaced};
|
use roc_parse::ast::{Collection, Module, Spaced};
|
||||||
use roc_parse::header::{
|
use roc_parse::header::{
|
||||||
|
@ -31,6 +31,8 @@ pub fn fmt_module<'a>(buf: &mut Buf<'_>, module: &'a Module<'a>) {
|
||||||
pub fn fmt_interface_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a InterfaceHeader<'a>) {
|
pub fn fmt_interface_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a InterfaceHeader<'a>) {
|
||||||
let indent = INDENT;
|
let indent = INDENT;
|
||||||
|
|
||||||
|
fmt_comments_only(buf, header.before_header.iter(), NewlineAt::Bottom, indent);
|
||||||
|
|
||||||
buf.indent(0);
|
buf.indent(0);
|
||||||
buf.push_str("interface");
|
buf.push_str("interface");
|
||||||
|
|
||||||
|
@ -56,6 +58,8 @@ pub fn fmt_interface_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a Interface
|
||||||
pub fn fmt_hosted_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a HostedHeader<'a>) {
|
pub fn fmt_hosted_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a HostedHeader<'a>) {
|
||||||
let indent = INDENT;
|
let indent = INDENT;
|
||||||
|
|
||||||
|
fmt_comments_only(buf, header.before_header.iter(), NewlineAt::Bottom, indent);
|
||||||
|
|
||||||
buf.indent(0);
|
buf.indent(0);
|
||||||
buf.push_str("hosted");
|
buf.push_str("hosted");
|
||||||
|
|
||||||
|
@ -94,6 +98,9 @@ pub fn fmt_hosted_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a HostedHeader
|
||||||
|
|
||||||
pub fn fmt_app_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a AppHeader<'a>) {
|
pub fn fmt_app_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a AppHeader<'a>) {
|
||||||
let indent = INDENT;
|
let indent = INDENT;
|
||||||
|
|
||||||
|
fmt_comments_only(buf, header.before_header.iter(), NewlineAt::Bottom, indent);
|
||||||
|
|
||||||
buf.indent(0);
|
buf.indent(0);
|
||||||
buf.push_str("app");
|
buf.push_str("app");
|
||||||
|
|
||||||
|
@ -130,6 +137,8 @@ pub fn fmt_app_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a AppHeader<'a>)
|
||||||
pub fn fmt_platform_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a PlatformHeader<'a>) {
|
pub fn fmt_platform_header<'a, 'buf>(buf: &mut Buf<'buf>, header: &'a PlatformHeader<'a>) {
|
||||||
let indent = INDENT;
|
let indent = INDENT;
|
||||||
|
|
||||||
|
fmt_comments_only(buf, header.before_header.iter(), NewlineAt::Bottom, indent);
|
||||||
|
|
||||||
buf.indent(0);
|
buf.indent(0);
|
||||||
buf.push_str("platform");
|
buf.push_str("platform");
|
||||||
|
|
||||||
|
|
|
@ -5615,6 +5615,37 @@ mod test_fmt {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn leading_comments_preserved() {
|
||||||
|
module_formats_same(indoc!(
|
||||||
|
r#"
|
||||||
|
# hello world
|
||||||
|
interface Foo
|
||||||
|
exposes []
|
||||||
|
imports []
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
module_formats_same(indoc!(
|
||||||
|
r#"
|
||||||
|
# hello world
|
||||||
|
app "test" packages {} imports [] provides [] to "./platform"
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
module_formats_same(indoc!(
|
||||||
|
r#"
|
||||||
|
# hello world
|
||||||
|
platform "hello-world"
|
||||||
|
requires {} { main : Str }
|
||||||
|
exposes []
|
||||||
|
packages {}
|
||||||
|
imports []
|
||||||
|
provides [mainForHost]
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// this is a parse error atm
|
// this is a parse error atm
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn multiline_apply() {
|
// fn multiline_apply() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue