Adjust parens around patterns in annotations

This commit is contained in:
Joshua Warner 2024-12-01 17:11:21 -08:00
parent b79d387b46
commit 84b3969648
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
23 changed files with 88 additions and 128 deletions

View file

@ -20,6 +20,38 @@ pub fn fmt_default_newline(buf: &mut Buf, spaces: &[CommentOrNewline], indent: u
}
}
pub enum SpacesNewlineMode {
Normal,
SkipNewlinesAtStart,
SkipNewlinesAtEnd,
SkipNewlinesAtBoth,
}
pub fn fmt_spaces_with_newline_mode(
buf: &mut Buf<'_>,
mut spaces: &[CommentOrNewline<'_>],
indent: u16,
mode: SpacesNewlineMode,
) {
if matches!(
mode,
SpacesNewlineMode::SkipNewlinesAtStart | SpacesNewlineMode::SkipNewlinesAtBoth
) {
while let Some(CommentOrNewline::Newline) = spaces.first() {
spaces = &spaces[1..];
}
}
if matches!(
mode,
SpacesNewlineMode::SkipNewlinesAtEnd | SpacesNewlineMode::SkipNewlinesAtBoth
) {
while let Some(CommentOrNewline::Newline) = spaces.last() {
spaces = &spaces[..spaces.len() - 1];
}
}
fmt_spaces(buf, spaces.iter(), indent);
}
/// Like fmt_spaces, but disallows two consecutive newlines.
pub fn fmt_spaces_no_blank_lines<'a, 'buf, I>(buf: &mut Buf<'buf>, spaces: I, indent: u16)
where