mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Remove lifetime from FormatContext (#4376)
This commit is contained in:
parent
6a52577630
commit
1ccef5150d
21 changed files with 124 additions and 138 deletions
|
@ -3,23 +3,21 @@ use std::rc::Rc;
|
||||||
use ruff_formatter::{FormatContext, SimpleFormatOptions};
|
use ruff_formatter::{FormatContext, SimpleFormatOptions};
|
||||||
use ruff_python_ast::source_code::Locator;
|
use ruff_python_ast::source_code::Locator;
|
||||||
|
|
||||||
pub struct ASTFormatContext<'a> {
|
pub struct ASTFormatContext {
|
||||||
options: SimpleFormatOptions,
|
options: SimpleFormatOptions,
|
||||||
contents: Rc<str>,
|
contents: Rc<str>,
|
||||||
locator: Locator<'a>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ASTFormatContext<'a> {
|
impl ASTFormatContext {
|
||||||
pub fn new(options: SimpleFormatOptions, locator: Locator<'a>) -> Self {
|
pub fn new(options: SimpleFormatOptions, contents: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
options,
|
options,
|
||||||
contents: Rc::from(locator.contents()),
|
contents: Rc::from(contents),
|
||||||
locator,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormatContext for ASTFormatContext<'_> {
|
impl FormatContext for ASTFormatContext {
|
||||||
type Options = SimpleFormatOptions;
|
type Options = SimpleFormatOptions;
|
||||||
|
|
||||||
fn options(&self) -> &Self::Options {
|
fn options(&self) -> &Self::Options {
|
||||||
|
@ -27,12 +25,12 @@ impl FormatContext for ASTFormatContext<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ASTFormatContext<'a> {
|
impl ASTFormatContext {
|
||||||
pub fn contents(&'a self) -> Rc<str> {
|
pub fn contents(&self) -> Rc<str> {
|
||||||
self.contents.clone()
|
self.contents.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn locator(&'a self) -> &'a Locator {
|
pub fn locator(&self) -> Locator {
|
||||||
&self.locator
|
Locator::new(&self.contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct FormatAlias<'a> {
|
||||||
item: &'a Alias,
|
item: &'a Alias,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Alias {
|
impl AsFormat<ASTFormatContext> for Alias {
|
||||||
type Format<'a> = FormatAlias<'a>;
|
type Format<'a> = FormatAlias<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -19,7 +19,7 @@ impl AsFormat<ASTFormatContext<'_>> for Alias {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatAlias<'_> {
|
impl Format<ASTFormatContext> for FormatAlias<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let alias = self.item;
|
let alias = self.item;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct FormatArg<'a> {
|
||||||
item: &'a Arg,
|
item: &'a Arg,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Arg {
|
impl AsFormat<ASTFormatContext> for Arg {
|
||||||
type Format<'a> = FormatArg<'a>;
|
type Format<'a> = FormatArg<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -19,7 +19,7 @@ impl AsFormat<ASTFormatContext<'_>> for Arg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatArg<'_> {
|
impl Format<ASTFormatContext> for FormatArg<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let arg = self.item;
|
let arg = self.item;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct FormatArguments<'a> {
|
||||||
item: &'a Arguments,
|
item: &'a Arguments,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Arguments {
|
impl AsFormat<ASTFormatContext> for Arguments {
|
||||||
type Format<'a> = FormatArguments<'a>;
|
type Format<'a> = FormatArguments<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -17,8 +17,8 @@ impl AsFormat<ASTFormatContext<'_>> for Arguments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatArguments<'_> {
|
impl Format<ASTFormatContext> for FormatArguments<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let args = self.item;
|
let args = self.item;
|
||||||
|
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub struct FormatBoolOp<'a> {
|
||||||
item: &'a BoolOp,
|
item: &'a BoolOp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for BoolOp {
|
impl AsFormat<ASTFormatContext> for BoolOp {
|
||||||
type Format<'a> = FormatBoolOp<'a>;
|
type Format<'a> = FormatBoolOp<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -18,7 +18,7 @@ impl AsFormat<ASTFormatContext<'_>> for BoolOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatBoolOp<'_> {
|
impl Format<ASTFormatContext> for FormatBoolOp<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let bool_op = self.item;
|
let bool_op = self.item;
|
||||||
write!(f, [leading_comments(bool_op)])?;
|
write!(f, [leading_comments(bool_op)])?;
|
||||||
|
|
|
@ -12,8 +12,8 @@ pub struct Block<'a> {
|
||||||
body: &'a Body,
|
body: &'a Body,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for Block<'_> {
|
impl Format<ASTFormatContext> for Block<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
for (i, stmt) in self.body.node.iter().enumerate() {
|
for (i, stmt) in self.body.node.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
write!(f, [hard_line_break()])?;
|
write!(f, [hard_line_break()])?;
|
||||||
|
@ -49,8 +49,8 @@ pub struct Statements<'a> {
|
||||||
suite: &'a [Stmt],
|
suite: &'a [Stmt],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for Statements<'_> {
|
impl Format<ASTFormatContext> for Statements<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
for (i, stmt) in self.suite.iter().enumerate() {
|
for (i, stmt) in self.suite.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
write!(f, [hard_line_break()])?;
|
write!(f, [hard_line_break()])?;
|
||||||
|
@ -70,8 +70,8 @@ pub struct Literal {
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for Literal {
|
impl Format<ASTFormatContext> for Literal {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let text = f.context().contents();
|
let text = f.context().contents();
|
||||||
|
|
||||||
f.write_element(FormatElement::StaticTextSlice {
|
f.write_element(FormatElement::StaticTextSlice {
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub struct FormatCmpOp<'a> {
|
||||||
item: &'a CmpOp,
|
item: &'a CmpOp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for CmpOp {
|
impl AsFormat<ASTFormatContext> for CmpOp {
|
||||||
type Format<'a> = FormatCmpOp<'a>;
|
type Format<'a> = FormatCmpOp<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -18,7 +18,7 @@ impl AsFormat<ASTFormatContext<'_>> for CmpOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatCmpOp<'_> {
|
impl Format<ASTFormatContext> for FormatCmpOp<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let cmp_op = self.item;
|
let cmp_op = self.item;
|
||||||
write!(f, [leading_comments(cmp_op)])?;
|
write!(f, [leading_comments(cmp_op)])?;
|
||||||
|
|
|
@ -11,8 +11,8 @@ pub struct LeadingComments<'a, T> {
|
||||||
item: &'a Attributed<T>,
|
item: &'a Attributed<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Format<ASTFormatContext<'_>> for LeadingComments<'_, T> {
|
impl<T> Format<ASTFormatContext> for LeadingComments<'_, T> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
for trivia in &self.item.trivia {
|
for trivia in &self.item.trivia {
|
||||||
if trivia.relationship.is_leading() {
|
if trivia.relationship.is_leading() {
|
||||||
match trivia.kind {
|
match trivia.kind {
|
||||||
|
@ -40,8 +40,8 @@ pub struct TrailingComments<'a, T> {
|
||||||
item: &'a Attributed<T>,
|
item: &'a Attributed<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Format<ASTFormatContext<'_>> for TrailingComments<'_, T> {
|
impl<T> Format<ASTFormatContext> for TrailingComments<'_, T> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
for trivia in &self.item.trivia {
|
for trivia in &self.item.trivia {
|
||||||
if trivia.relationship.is_trailing() {
|
if trivia.relationship.is_trailing() {
|
||||||
match trivia.kind {
|
match trivia.kind {
|
||||||
|
@ -69,8 +69,8 @@ pub struct EndOfLineComments<'a, T> {
|
||||||
item: &'a Attributed<T>,
|
item: &'a Attributed<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Format<ASTFormatContext<'_>> for EndOfLineComments<'_, T> {
|
impl<T> Format<ASTFormatContext> for EndOfLineComments<'_, T> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for range in self
|
for range in self
|
||||||
.item
|
.item
|
||||||
|
@ -97,8 +97,8 @@ pub struct DanglingComments<'a, T> {
|
||||||
item: &'a Attributed<T>,
|
item: &'a Attributed<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Format<ASTFormatContext<'_>> for DanglingComments<'_, T> {
|
impl<T> Format<ASTFormatContext> for DanglingComments<'_, T> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
for trivia in &self.item.trivia {
|
for trivia in &self.item.trivia {
|
||||||
if trivia.relationship.is_dangling() {
|
if trivia.relationship.is_dangling() {
|
||||||
if let TriviaKind::OwnLineComment(range) = trivia.kind {
|
if let TriviaKind::OwnLineComment(range) = trivia.kind {
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct FormatComprehension<'a> {
|
||||||
item: &'a Comprehension,
|
item: &'a Comprehension,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Comprehension {
|
impl AsFormat<ASTFormatContext> for Comprehension {
|
||||||
type Format<'a> = FormatComprehension<'a>;
|
type Format<'a> = FormatComprehension<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -17,8 +17,8 @@ impl AsFormat<ASTFormatContext<'_>> for Comprehension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatComprehension<'_> {
|
impl Format<ASTFormatContext> for FormatComprehension<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let comprehension = self.item;
|
let comprehension = self.item;
|
||||||
|
|
||||||
write!(f, [soft_line_break_or_space()])?;
|
write!(f, [soft_line_break_or_space()])?;
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub struct FormatExcepthandler<'a> {
|
||||||
item: &'a Excepthandler,
|
item: &'a Excepthandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Excepthandler {
|
impl AsFormat<ASTFormatContext> for Excepthandler {
|
||||||
type Format<'a> = FormatExcepthandler<'a>;
|
type Format<'a> = FormatExcepthandler<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -20,7 +20,7 @@ impl AsFormat<ASTFormatContext<'_>> for Excepthandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatExcepthandler<'_> {
|
impl Format<ASTFormatContext> for FormatExcepthandler<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let excepthandler = self.item;
|
let excepthandler = self.item;
|
||||||
let ExcepthandlerKind::ExceptHandler { type_, name, body } = &excepthandler.node;
|
let ExcepthandlerKind::ExceptHandler { type_, name, body } = &excepthandler.node;
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub struct FormatExpr<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_starred(
|
fn format_starred(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -33,18 +33,14 @@ fn format_starred(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_name(
|
fn format_name(f: &mut Formatter<ASTFormatContext>, expr: &Expr, _id: &str) -> FormatResult<()> {
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
|
||||||
expr: &Expr,
|
|
||||||
_id: &str,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
write!(f, [literal(expr.range())])?;
|
write!(f, [literal(expr.range())])?;
|
||||||
write!(f, [end_of_line_comments(expr)])?;
|
write!(f, [end_of_line_comments(expr)])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_subscript(
|
fn format_subscript(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
slice: &Expr,
|
slice: &Expr,
|
||||||
|
@ -76,7 +72,7 @@ fn format_subscript(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_tuple(
|
fn format_tuple(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
elts: &[Expr],
|
elts: &[Expr],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -97,7 +93,7 @@ fn format_tuple(
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
[group(&format_with(
|
[group(&format_with(
|
||||||
|f: &mut Formatter<ASTFormatContext<'_>>| {
|
|f: &mut Formatter<ASTFormatContext>| {
|
||||||
if expr.parentheses.is_if_expanded() {
|
if expr.parentheses.is_if_expanded() {
|
||||||
write!(f, [if_group_breaks(&text("("))])?;
|
write!(f, [if_group_breaks(&text("("))])?;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +104,7 @@ fn format_tuple(
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
[soft_block_indent(&format_with(
|
[soft_block_indent(&format_with(
|
||||||
|f: &mut Formatter<ASTFormatContext<'_>>| {
|
|f: &mut Formatter<ASTFormatContext>| {
|
||||||
let magic_trailing_comma = expr
|
let magic_trailing_comma = expr
|
||||||
.trivia
|
.trivia
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -164,7 +160,7 @@ fn format_tuple(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_slice(
|
fn format_slice(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
lower: &SliceIndex,
|
lower: &SliceIndex,
|
||||||
upper: &SliceIndex,
|
upper: &SliceIndex,
|
||||||
|
@ -247,7 +243,7 @@ fn format_slice(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_formatted_value(
|
fn format_formatted_value(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
_conversion: usize,
|
_conversion: usize,
|
||||||
|
@ -263,7 +259,7 @@ fn format_formatted_value(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_list(
|
fn format_list(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
elts: &[Expr],
|
elts: &[Expr],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -294,11 +290,7 @@ fn format_list(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_set(
|
fn format_set(f: &mut Formatter<ASTFormatContext>, expr: &Expr, elts: &[Expr]) -> FormatResult<()> {
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
|
||||||
expr: &Expr,
|
|
||||||
elts: &[Expr],
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
if elts.is_empty() {
|
if elts.is_empty() {
|
||||||
write!(f, [text("set()")])?;
|
write!(f, [text("set()")])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -333,7 +325,7 @@ fn format_set(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_call(
|
fn format_call(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
func: &Expr,
|
func: &Expr,
|
||||||
args: &[Expr],
|
args: &[Expr],
|
||||||
|
@ -396,7 +388,7 @@ fn format_call(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_list_comp(
|
fn format_list_comp(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
elt: &Expr,
|
elt: &Expr,
|
||||||
generators: &[Comprehension],
|
generators: &[Comprehension],
|
||||||
|
@ -417,7 +409,7 @@ fn format_list_comp(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_set_comp(
|
fn format_set_comp(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
elt: &Expr,
|
elt: &Expr,
|
||||||
generators: &[Comprehension],
|
generators: &[Comprehension],
|
||||||
|
@ -438,7 +430,7 @@ fn format_set_comp(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_dict_comp(
|
fn format_dict_comp(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
key: &Expr,
|
key: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
|
@ -463,7 +455,7 @@ fn format_dict_comp(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_generator_exp(
|
fn format_generator_exp(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
elt: &Expr,
|
elt: &Expr,
|
||||||
generators: &[Comprehension],
|
generators: &[Comprehension],
|
||||||
|
@ -482,7 +474,7 @@ fn format_generator_exp(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_await(
|
fn format_await(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -504,7 +496,7 @@ fn format_await(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_yield(
|
fn format_yield(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: Option<&Expr>,
|
value: Option<&Expr>,
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -528,7 +520,7 @@ fn format_yield(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_yield_from(
|
fn format_yield_from(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -558,7 +550,7 @@ fn format_yield_from(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_compare(
|
fn format_compare(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
left: &Expr,
|
left: &Expr,
|
||||||
ops: &[CmpOp],
|
ops: &[CmpOp],
|
||||||
|
@ -578,7 +570,7 @@ fn format_compare(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_joined_str(
|
fn format_joined_str(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
_values: &[Expr],
|
_values: &[Expr],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -588,7 +580,7 @@ fn format_joined_str(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_constant(
|
fn format_constant(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
constant: &Constant,
|
constant: &Constant,
|
||||||
_kind: Option<&str>,
|
_kind: Option<&str>,
|
||||||
|
@ -615,7 +607,7 @@ fn format_constant(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_dict(
|
fn format_dict(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
keys: &[Option<Expr>],
|
keys: &[Option<Expr>],
|
||||||
values: &[Expr],
|
values: &[Expr],
|
||||||
|
@ -677,7 +669,7 @@ fn format_dict(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_attribute(
|
fn format_attribute(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
attr: &str,
|
attr: &str,
|
||||||
|
@ -690,7 +682,7 @@ fn format_attribute(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_named_expr(
|
fn format_named_expr(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
target: &Expr,
|
target: &Expr,
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
|
@ -704,7 +696,7 @@ fn format_named_expr(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_bool_op(
|
fn format_bool_op(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
ops: &[BoolOp],
|
ops: &[BoolOp],
|
||||||
values: &[Expr],
|
values: &[Expr],
|
||||||
|
@ -721,7 +713,7 @@ fn format_bool_op(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_bin_op(
|
fn format_bin_op(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
left: &Expr,
|
left: &Expr,
|
||||||
op: &Operator,
|
op: &Operator,
|
||||||
|
@ -744,7 +736,7 @@ fn format_bin_op(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_unary_op(
|
fn format_unary_op(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
op: &UnaryOp,
|
op: &UnaryOp,
|
||||||
operand: &Expr,
|
operand: &Expr,
|
||||||
|
@ -773,7 +765,7 @@ fn format_unary_op(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_lambda(
|
fn format_lambda(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
args: &Arguments,
|
args: &Arguments,
|
||||||
body: &Expr,
|
body: &Expr,
|
||||||
|
@ -791,7 +783,7 @@ fn format_lambda(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_if_exp(
|
fn format_if_exp(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
test: &Expr,
|
test: &Expr,
|
||||||
body: &Expr,
|
body: &Expr,
|
||||||
|
@ -809,8 +801,8 @@ fn format_if_exp(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatExpr<'_> {
|
impl Format<ASTFormatContext> for FormatExpr<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
if self.item.parentheses.is_always() {
|
if self.item.parentheses.is_always() {
|
||||||
write!(f, [text("(")])?;
|
write!(f, [text("(")])?;
|
||||||
}
|
}
|
||||||
|
@ -894,7 +886,7 @@ impl Format<ASTFormatContext<'_>> for FormatExpr<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Expr {
|
impl AsFormat<ASTFormatContext> for Expr {
|
||||||
type Format<'a> = FormatExpr<'a>;
|
type Format<'a> = FormatExpr<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct FormatKeyword<'a> {
|
||||||
item: &'a Keyword,
|
item: &'a Keyword,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Keyword {
|
impl AsFormat<ASTFormatContext> for Keyword {
|
||||||
type Format<'a> = FormatKeyword<'a>;
|
type Format<'a> = FormatKeyword<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -19,7 +19,7 @@ impl AsFormat<ASTFormatContext<'_>> for Keyword {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatKeyword<'_> {
|
impl Format<ASTFormatContext> for FormatKeyword<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let keyword = self.item;
|
let keyword = self.item;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct FormatMatchCase<'a> {
|
||||||
item: &'a MatchCase,
|
item: &'a MatchCase,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for MatchCase {
|
impl AsFormat<ASTFormatContext> for MatchCase {
|
||||||
type Format<'a> = FormatMatchCase<'a>;
|
type Format<'a> = FormatMatchCase<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -19,7 +19,7 @@ impl AsFormat<ASTFormatContext<'_>> for MatchCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatMatchCase<'_> {
|
impl Format<ASTFormatContext> for FormatMatchCase<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let MatchCase {
|
let MatchCase {
|
||||||
pattern,
|
pattern,
|
||||||
|
|
|
@ -12,8 +12,8 @@ struct FloatAtom {
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FloatAtom {
|
impl Format<ASTFormatContext> for FloatAtom {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let contents = f.context().contents();
|
let contents = f.context().contents();
|
||||||
|
|
||||||
let content = &contents[self.range];
|
let content = &contents[self.range];
|
||||||
|
@ -68,8 +68,8 @@ pub struct FloatLiteral {
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FloatLiteral {
|
impl Format<ASTFormatContext> for FloatLiteral {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let contents = f.context().contents();
|
let contents = f.context().contents();
|
||||||
|
|
||||||
let content = &contents[self.range];
|
let content = &contents[self.range];
|
||||||
|
@ -118,8 +118,8 @@ pub struct IntLiteral {
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for IntLiteral {
|
impl Format<ASTFormatContext> for IntLiteral {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let contents = f.context().contents();
|
let contents = f.context().contents();
|
||||||
|
|
||||||
for prefix in ["0b", "0B", "0o", "0O", "0x", "0X"] {
|
for prefix in ["0b", "0B", "0o", "0O", "0x", "0X"] {
|
||||||
|
@ -165,8 +165,8 @@ pub struct ComplexLiteral {
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for ComplexLiteral {
|
impl Format<ASTFormatContext> for ComplexLiteral {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let contents = f.context().contents();
|
let contents = f.context().contents();
|
||||||
let content = &contents[self.range];
|
let content = &contents[self.range];
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub struct FormatOperator<'a> {
|
||||||
item: &'a Operator,
|
item: &'a Operator,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Operator {
|
impl AsFormat<ASTFormatContext> for Operator {
|
||||||
type Format<'a> = FormatOperator<'a>;
|
type Format<'a> = FormatOperator<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -18,8 +18,8 @@ impl AsFormat<ASTFormatContext<'_>> for Operator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatOperator<'_> {
|
impl Format<ASTFormatContext> for FormatOperator<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let operator = self.item;
|
let operator = self.item;
|
||||||
write!(f, [leading_comments(operator)])?;
|
write!(f, [leading_comments(operator)])?;
|
||||||
write!(
|
write!(
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub struct FormatPattern<'a> {
|
||||||
item: &'a Pattern,
|
item: &'a Pattern,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Pattern {
|
impl AsFormat<ASTFormatContext> for Pattern {
|
||||||
type Format<'a> = FormatPattern<'a>;
|
type Format<'a> = FormatPattern<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -20,7 +20,7 @@ impl AsFormat<ASTFormatContext<'_>> for Pattern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatPattern<'_> {
|
impl Format<ASTFormatContext> for FormatPattern<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let pattern = self.item;
|
let pattern = self.item;
|
||||||
|
|
||||||
|
|
|
@ -14,26 +14,26 @@ use crate::format::comments::{end_of_line_comments, leading_comments, trailing_c
|
||||||
use crate::format::helpers::is_self_closing;
|
use crate::format::helpers::is_self_closing;
|
||||||
use crate::shared_traits::AsFormat;
|
use crate::shared_traits::AsFormat;
|
||||||
|
|
||||||
fn format_break(f: &mut Formatter<ASTFormatContext<'_>>, stmt: &Stmt) -> FormatResult<()> {
|
fn format_break(f: &mut Formatter<ASTFormatContext>, stmt: &Stmt) -> FormatResult<()> {
|
||||||
write!(f, [text("break")])?;
|
write!(f, [text("break")])?;
|
||||||
write!(f, [end_of_line_comments(stmt)])?;
|
write!(f, [end_of_line_comments(stmt)])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_pass(f: &mut Formatter<ASTFormatContext<'_>>, stmt: &Stmt) -> FormatResult<()> {
|
fn format_pass(f: &mut Formatter<ASTFormatContext>, stmt: &Stmt) -> FormatResult<()> {
|
||||||
write!(f, [text("pass")])?;
|
write!(f, [text("pass")])?;
|
||||||
write!(f, [end_of_line_comments(stmt)])?;
|
write!(f, [end_of_line_comments(stmt)])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_continue(f: &mut Formatter<ASTFormatContext<'_>>, stmt: &Stmt) -> FormatResult<()> {
|
fn format_continue(f: &mut Formatter<ASTFormatContext>, stmt: &Stmt) -> FormatResult<()> {
|
||||||
write!(f, [text("continue")])?;
|
write!(f, [text("continue")])?;
|
||||||
write!(f, [end_of_line_comments(stmt)])?;
|
write!(f, [end_of_line_comments(stmt)])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_global(
|
fn format_global(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
names: &[String],
|
names: &[String],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -46,7 +46,7 @@ fn format_global(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_nonlocal(
|
fn format_nonlocal(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
names: &[String],
|
names: &[String],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -59,7 +59,7 @@ fn format_nonlocal(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_delete(
|
fn format_delete(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
targets: &[Expr],
|
targets: &[Expr],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -97,7 +97,7 @@ fn format_delete(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_class_def(
|
fn format_class_def(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
name: &str,
|
name: &str,
|
||||||
bases: &[Expr],
|
bases: &[Expr],
|
||||||
keywords: &[Keyword],
|
keywords: &[Keyword],
|
||||||
|
@ -157,7 +157,7 @@ fn format_class_def(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_func_def(
|
fn format_func_def(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
name: &str,
|
name: &str,
|
||||||
args: &Arguments,
|
args: &Arguments,
|
||||||
|
@ -204,7 +204,7 @@ fn format_func_def(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_assign(
|
fn format_assign(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
targets: &[Expr],
|
targets: &[Expr],
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
|
@ -236,7 +236,7 @@ fn format_assign(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_aug_assign(
|
fn format_aug_assign(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
target: &Expr,
|
target: &Expr,
|
||||||
op: &Operator,
|
op: &Operator,
|
||||||
|
@ -264,7 +264,7 @@ fn format_aug_assign(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_ann_assign(
|
fn format_ann_assign(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
target: &Expr,
|
target: &Expr,
|
||||||
annotation: &Expr,
|
annotation: &Expr,
|
||||||
|
@ -301,7 +301,7 @@ fn format_ann_assign(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_for(
|
fn format_for(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
target: &Expr,
|
target: &Expr,
|
||||||
iter: &Expr,
|
iter: &Expr,
|
||||||
|
@ -342,7 +342,7 @@ fn format_for(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_while(
|
fn format_while(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
test: &Expr,
|
test: &Expr,
|
||||||
body: &Body,
|
body: &Body,
|
||||||
|
@ -383,7 +383,7 @@ fn format_while(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_if(
|
fn format_if(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
test: &Expr,
|
test: &Expr,
|
||||||
body: &Body,
|
body: &Body,
|
||||||
orelse: Option<&Body>,
|
orelse: Option<&Body>,
|
||||||
|
@ -449,7 +449,7 @@ fn format_if(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_match(
|
fn format_match(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
subject: &Expr,
|
subject: &Expr,
|
||||||
cases: &[MatchCase],
|
cases: &[MatchCase],
|
||||||
|
@ -471,7 +471,7 @@ fn format_match(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_raise(
|
fn format_raise(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
exc: Option<&Expr>,
|
exc: Option<&Expr>,
|
||||||
cause: Option<&Expr>,
|
cause: Option<&Expr>,
|
||||||
|
@ -487,7 +487,7 @@ fn format_raise(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_return(
|
fn format_return(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
value: Option<&Expr>,
|
value: Option<&Expr>,
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -502,7 +502,7 @@ fn format_return(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_try(
|
fn format_try(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
body: &Body,
|
body: &Body,
|
||||||
handlers: &[Excepthandler],
|
handlers: &[Excepthandler],
|
||||||
|
@ -534,7 +534,7 @@ fn format_try(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_try_star(
|
fn format_try_star(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
body: &Body,
|
body: &Body,
|
||||||
handlers: &[Excepthandler],
|
handlers: &[Excepthandler],
|
||||||
|
@ -577,7 +577,7 @@ fn format_try_star(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_assert(
|
fn format_assert(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
test: &Expr,
|
test: &Expr,
|
||||||
msg: Option<&Expr>,
|
msg: Option<&Expr>,
|
||||||
|
@ -609,7 +609,7 @@ fn format_assert(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_import(
|
fn format_import(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
names: &[Alias],
|
names: &[Alias],
|
||||||
) -> FormatResult<()> {
|
) -> FormatResult<()> {
|
||||||
|
@ -638,7 +638,7 @@ fn format_import(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_import_from(
|
fn format_import_from(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
module: Option<&str>,
|
module: Option<&str>,
|
||||||
names: &[Alias],
|
names: &[Alias],
|
||||||
|
@ -693,11 +693,7 @@ fn format_import_from(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_expr(
|
fn format_expr(f: &mut Formatter<ASTFormatContext>, stmt: &Stmt, expr: &Expr) -> FormatResult<()> {
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
|
||||||
stmt: &Stmt,
|
|
||||||
expr: &Expr,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
if stmt.parentheses.is_always() {
|
if stmt.parentheses.is_always() {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -726,7 +722,7 @@ fn format_expr(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_with_(
|
fn format_with_(
|
||||||
f: &mut Formatter<ASTFormatContext<'_>>,
|
f: &mut Formatter<ASTFormatContext>,
|
||||||
stmt: &Stmt,
|
stmt: &Stmt,
|
||||||
items: &[Withitem],
|
items: &[Withitem],
|
||||||
body: &Body,
|
body: &Body,
|
||||||
|
@ -768,8 +764,8 @@ pub struct FormatStmt<'a> {
|
||||||
item: &'a Stmt,
|
item: &'a Stmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatStmt<'_> {
|
impl Format<ASTFormatContext> for FormatStmt<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
write!(f, [leading_comments(self.item)])?;
|
write!(f, [leading_comments(self.item)])?;
|
||||||
|
|
||||||
match &self.item.node {
|
match &self.item.node {
|
||||||
|
@ -951,7 +947,7 @@ impl Format<ASTFormatContext<'_>> for FormatStmt<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Stmt {
|
impl AsFormat<ASTFormatContext> for Stmt {
|
||||||
type Format<'a> = FormatStmt<'a>;
|
type Format<'a> = FormatStmt<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
|
|
@ -13,8 +13,8 @@ pub struct StringLiteralPart {
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for StringLiteralPart {
|
impl Format<ASTFormatContext> for StringLiteralPart {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let contents = f.context().contents();
|
let contents = f.context().contents();
|
||||||
|
|
||||||
// Extract leading and trailing quotes.
|
// Extract leading and trailing quotes.
|
||||||
|
@ -119,8 +119,8 @@ pub struct StringLiteral<'a> {
|
||||||
expr: &'a Expr,
|
expr: &'a Expr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for StringLiteral<'_> {
|
impl Format<ASTFormatContext> for StringLiteral<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let expr = self.expr;
|
let expr = self.expr;
|
||||||
|
|
||||||
// TODO(charlie): This tokenization needs to happen earlier, so that we can attach
|
// TODO(charlie): This tokenization needs to happen earlier, so that we can attach
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct FormatUnaryOp<'a> {
|
||||||
item: &'a UnaryOp,
|
item: &'a UnaryOp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for UnaryOp {
|
impl AsFormat<ASTFormatContext> for UnaryOp {
|
||||||
type Format<'a> = FormatUnaryOp<'a>;
|
type Format<'a> = FormatUnaryOp<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -17,7 +17,7 @@ impl AsFormat<ASTFormatContext<'_>> for UnaryOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatUnaryOp<'_> {
|
impl Format<ASTFormatContext> for FormatUnaryOp<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let unary_op = self.item;
|
let unary_op = self.item;
|
||||||
write!(
|
write!(
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct FormatWithitem<'a> {
|
||||||
item: &'a Withitem,
|
item: &'a Withitem,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsFormat<ASTFormatContext<'_>> for Withitem {
|
impl AsFormat<ASTFormatContext> for Withitem {
|
||||||
type Format<'a> = FormatWithitem<'a>;
|
type Format<'a> = FormatWithitem<'a>;
|
||||||
|
|
||||||
fn format(&self) -> Self::Format<'_> {
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
@ -17,7 +17,7 @@ impl AsFormat<ASTFormatContext<'_>> for Withitem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<ASTFormatContext<'_>> for FormatWithitem<'_> {
|
impl Format<ASTFormatContext> for FormatWithitem<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
fn fmt(&self, f: &mut Formatter<ASTFormatContext>) -> FormatResult<()> {
|
||||||
let withitem = self.item;
|
let withitem = self.item;
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
|
||||||
indent_style: IndentStyle::Space(4),
|
indent_style: IndentStyle::Space(4),
|
||||||
line_width: 88.try_into().unwrap(),
|
line_width: 88.try_into().unwrap(),
|
||||||
},
|
},
|
||||||
locator,
|
locator.contents(),
|
||||||
),
|
),
|
||||||
[format::builders::statements(&python_cst)]
|
[format::builders::statements(&python_cst)]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue