Parse and format inline ingested file imports

This commit is contained in:
Agus Zubiaga 2023-12-10 01:23:57 -03:00
parent 42e755677c
commit 4d6e641864
No known key found for this signature in database
10 changed files with 165 additions and 12 deletions

View file

@ -1,5 +1,6 @@
use crate::annotation::{is_collection_multiline, Formattable, Newlines, Parens};
use crate::collection::{fmt_collection, Braces};
use crate::expr::fmt_str_literal;
use crate::pattern::fmt_pattern;
use crate::spaces::{fmt_default_newline, fmt_default_spaces, fmt_spaces, INDENT};
use crate::Buf;
@ -287,6 +288,11 @@ impl<'a> Formattable for ValueDef<'a> {
a.keyword.is_multiline() || is_collection_multiline(&a.item)
})
}
IngestedFileImport {
before_path,
path: _,
name,
} => !before_path.is_empty() || name.is_multiline(),
}
}
@ -365,6 +371,20 @@ impl<'a> Formattable for ValueDef<'a> {
fmt_collection(buf, list_indent, Braces::Square, exposed.item, Newlines::No);
}
}
IngestedFileImport {
before_path,
path,
name,
} => {
buf.indent(indent);
buf.push_str("import");
let indent = indent + INDENT;
fmt_default_spaces(buf, before_path, indent);
fmt_str_literal(buf, path.value, indent);
name.format(buf, indent);
}
}
}
}