Support fmt: skip on compound statements (#6593)

This commit is contained in:
Micha Reiser 2023-08-17 08:05:41 +02:00 committed by GitHub
parent 4dc32a00d0
commit fa7442da2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1385 additions and 625 deletions

View file

@ -15,6 +15,7 @@ use ruff_text_size::{TextRange, TextSize};
use crate::comments::format::{empty_lines, format_comment};
use crate::comments::{leading_comments, trailing_comments, SourceComment};
use crate::prelude::*;
use crate::statement::clause::ClauseHeader;
use crate::statement::suite::SuiteChildStatement;
/// Disables formatting for all statements between the `first_suppressed` that has a leading `fmt: off` comment
@ -930,3 +931,28 @@ impl Format<PyFormatContext<'_>> for FormatSuppressedNode<'_> {
)
}
}
#[cold]
pub(crate) fn write_suppressed_clause_header(
header: ClauseHeader,
f: &mut PyFormatter,
) -> FormatResult<()> {
// Write the outer comments and format the node as verbatim
write!(
f,
[verbatim_text(
header.range(f.context().source())?,
ContainsNewlines::Detect
),]
)?;
let comments = f.context().comments();
header.visit(&mut |child| {
for comment in comments.leading_trailing_comments(child) {
comment.mark_formatted();
}
comments.mark_verbatim_node_comments_formatted(child);
});
Ok(())
}