Track formatting all comments

We currently don't format all comments as match statements are not yet implemented. We can work around this for the top level match statement by setting them manually formatted but the mocked-out top level match doesn't call into its children so they would still have unformatted comments
This commit is contained in:
konsti 2023-08-10 09:19:27 +02:00 committed by GitHub
parent e2f7862404
commit 39beeb61f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 25 deletions

View file

@ -14,7 +14,7 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
fn fmt_fields(&self, item: &MatchCase, f: &mut PyFormatter) -> FormatResult<()> {
let MatchCase {
range: _,
pattern: _,
pattern,
guard,
body,
} = item;
@ -24,7 +24,17 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
[
text("case"),
space(),
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern"),
format_with(|f: &mut PyFormatter| {
let comments = f.context().comments();
for comment in comments.leading_trailing_comments(pattern) {
// This is a lie, but let's go with it.
comment.mark_formatted();
}
// Replace the whole `format_with` with `pattern.format()` once pattern formatting is implemented.
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern", pattern).fmt(f)
}),
]
)?;