Range formatting API (#9635)

This commit is contained in:
Micha Reiser 2024-01-31 11:13:37 +01:00 committed by GitHub
parent 6bb126415d
commit ce14f4dea5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
65 changed files with 3273 additions and 762 deletions

View file

@ -1,6 +1,7 @@
use ruff_formatter::{format_args, write};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{ElifElseClause, StmtIf};
use ruff_text_size::Ranged;
use crate::comments::SourceComment;
use crate::expression::maybe_parenthesize_expression;
@ -81,7 +82,12 @@ pub(crate) fn format_elif_else_clause(
clause_header(
ClauseHeader::ElifElse(item),
trailing_colon_comment,
&format_with(|f| {
&format_with(|f: &mut PyFormatter| {
f.options()
.source_map_generation()
.is_enabled()
.then_some(source_position(item.start()))
.fmt(f)?;
if let Some(test) = test {
write!(
f,
@ -98,6 +104,10 @@ pub(crate) fn format_elif_else_clause(
)
.with_leading_comments(leading_comments, last_node),
clause_body(body, trailing_colon_comment),
f.options()
.source_map_generation()
.is_enabled()
.then_some(source_position(item.end()))
]
)
}