mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Add StaticTextSlice
kind to FormatElement
enum (#2873)
Given our current parser abstractions, we need the ability to tell `ruff_formatter` to print a pre-defined slice from a fixed string of source code, which we've introduced here as `FormatElement::StaticTextSlice`.
This commit is contained in:
parent
746e1d3436
commit
98ea94fdb7
4 changed files with 44 additions and 1 deletions
|
@ -81,6 +81,7 @@ impl Document {
|
|||
}
|
||||
FormatElement::StaticText { text } => text.contains('\n'),
|
||||
FormatElement::DynamicText { text, .. } => text.contains('\n'),
|
||||
FormatElement::StaticTextSlice { text, range } => text[*range].contains('\n'),
|
||||
FormatElement::SyntaxTokenTextSlice { slice, .. } => slice.contains('\n'),
|
||||
FormatElement::ExpandParent
|
||||
| FormatElement::Line(LineMode::Hard | LineMode::Empty) => true,
|
||||
|
@ -194,6 +195,7 @@ impl Format<IrFormatContext> for &[FormatElement] {
|
|||
element @ FormatElement::Space
|
||||
| element @ FormatElement::StaticText { .. }
|
||||
| element @ FormatElement::DynamicText { .. }
|
||||
| element @ FormatElement::StaticTextSlice { .. }
|
||||
| element @ FormatElement::SyntaxTokenTextSlice { .. } => {
|
||||
if !in_text {
|
||||
write!(f, [text("\"")])?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue