mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Move MigrationFlags from an argument on format* to a field on Buf
That has a few advantages: * We avoid a bunch of extra parameter-passing "noise", since the vast majority of formatting code doesn't need to care about this setting beyond just passing it to nested format calls. * It aligns really well with the "global" nature of this setting, and makes it impossible to have bugs where e.g. one callsite forgets to pass the correct value to it's children - which would lead to parts of the tree not being migrated. If this is truly a global setting on Buf, that simply can't happen.
This commit is contained in:
parent
0274d9b997
commit
120e9be550
15 changed files with 390 additions and 812 deletions
|
@ -19,19 +19,40 @@ pub struct Buf<'a> {
|
|||
newlines_to_flush: usize,
|
||||
beginning_of_line: bool,
|
||||
line_indent: u16,
|
||||
flags: MigrationFlags,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct MigrationFlags {
|
||||
pub(crate) snakify: bool,
|
||||
}
|
||||
|
||||
impl MigrationFlags {
|
||||
pub fn new(snakify: bool) -> Self {
|
||||
MigrationFlags { snakify }
|
||||
}
|
||||
|
||||
pub fn at_least_one_active(&self) -> bool {
|
||||
self.snakify
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Buf<'a> {
|
||||
pub fn new_in(arena: &'a Bump) -> Buf<'a> {
|
||||
pub fn new_in(arena: &'a Bump, flags: MigrationFlags) -> Buf<'a> {
|
||||
Buf {
|
||||
text: String::new_in(arena),
|
||||
line_indent: 0,
|
||||
spaces_to_flush: 0,
|
||||
newlines_to_flush: 0,
|
||||
beginning_of_line: true,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flags(&self) -> MigrationFlags {
|
||||
self.flags
|
||||
}
|
||||
|
||||
pub fn as_str(&'a self) -> &'a str {
|
||||
self.text.as_str()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue