Skip to content

Commit c05e462

Browse files
authored
Introduce Token element (#7048)
1 parent 2f3a950 commit c05e462

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+733
-723
lines changed

crates/ruff_formatter/src/arguments.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'fmt, Context> Argument<'fmt, Context> {
7070
///
7171
/// # fn main() -> FormatResult<()> {
7272
/// let formatted = format!(SimpleFormatContext::default(), [
73-
/// format_args!(text("a"), space(), text("b"))
73+
/// format_args!(token("a"), space(), token("b"))
7474
/// ])?;
7575
///
7676
/// assert_eq!("a b", formatted.print()?.as_code());
@@ -135,26 +135,26 @@ mod tests {
135135
write!(
136136
&mut buffer,
137137
[
138-
text("function"),
138+
token("function"),
139139
space(),
140-
text("a"),
140+
token("a"),
141141
space(),
142-
group(&format_args!(text("("), text(")")))
142+
group(&format_args!(token("("), token(")")))
143143
]
144144
)
145145
.unwrap();
146146

147147
assert_eq!(
148148
buffer.into_vec(),
149149
vec![
150-
FormatElement::StaticText { text: "function" },
150+
FormatElement::Token { text: "function" },
151151
FormatElement::Space,
152-
FormatElement::StaticText { text: "a" },
152+
FormatElement::Token { text: "a" },
153153
FormatElement::Space,
154154
// Group
155155
FormatElement::Tag(Tag::StartGroup(tag::Group::new())),
156-
FormatElement::StaticText { text: "(" },
157-
FormatElement::StaticText { text: ")" },
156+
FormatElement::Token { text: "(" },
157+
FormatElement::Token { text: ")" },
158158
FormatElement::Tag(Tag::EndGroup)
159159
]
160160
);

crates/ruff_formatter/src/buffer.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ pub trait Buffer {
2525
/// let mut state = FormatState::new(SimpleFormatContext::default());
2626
/// let mut buffer = VecBuffer::new(&mut state);
2727
///
28-
/// buffer.write_element(FormatElement::StaticText { text: "test"});
28+
/// buffer.write_element(FormatElement::Token { text: "test"});
2929
///
30-
/// assert_eq!(buffer.into_vec(), vec![FormatElement::StaticText { text: "test" }]);
30+
/// assert_eq!(buffer.into_vec(), vec![FormatElement::Token { text: "test" }]);
3131
/// ```
3232
fn write_element(&mut self, element: FormatElement);
3333

@@ -50,9 +50,9 @@ pub trait Buffer {
5050
/// let mut state = FormatState::new(SimpleFormatContext::default());
5151
/// let mut buffer = VecBuffer::new(&mut state);
5252
///
53-
/// buffer.write_fmt(format_args!(text("Hello World"))).unwrap();
53+
/// buffer.write_fmt(format_args!(token("Hello World"))).unwrap();
5454
///
55-
/// assert_eq!(buffer.into_vec(), vec![FormatElement::StaticText{ text: "Hello World" }]);
55+
/// assert_eq!(buffer.into_vec(), vec![FormatElement::Token{ text: "Hello World" }]);
5656
/// ```
5757
fn write_fmt(mut self: &mut Self, arguments: Arguments<Self::Context>) -> FormatResult<()> {
5858
write(&mut self, arguments)
@@ -316,11 +316,11 @@ where
316316
/// write!(
317317
/// buffer,
318318
/// [
319-
/// text("The next soft line or space gets replaced by a space"),
319+
/// token("The next soft line or space gets replaced by a space"),
320320
/// soft_line_break_or_space(),
321-
/// text("and the line here"),
321+
/// token("and the line here"),
322322
/// soft_line_break(),
323-
/// text("is removed entirely.")
323+
/// token("is removed entirely.")
324324
/// ]
325325
/// )
326326
/// })]
@@ -329,10 +329,10 @@ where
329329
/// assert_eq!(
330330
/// formatted.document().as_ref(),
331331
/// &[
332-
/// FormatElement::StaticText { text: "The next soft line or space gets replaced by a space" },
332+
/// FormatElement::Token { text: "The next soft line or space gets replaced by a space" },
333333
/// FormatElement::Space,
334-
/// FormatElement::StaticText { text: "and the line here" },
335-
/// FormatElement::StaticText { text: "is removed entirely." }
334+
/// FormatElement::Token { text: "and the line here" },
335+
/// FormatElement::Token { text: "is removed entirely." }
336336
/// ]
337337
/// );
338338
///
@@ -488,19 +488,19 @@ pub trait BufferExtensions: Buffer + Sized {
488488
/// let formatted = format!(SimpleFormatContext::default(), [format_with(|f| {
489489
/// let mut recording = f.start_recording();
490490
///
491-
/// write!(recording, [text("A")])?;
492-
/// write!(recording, [text("B")])?;
491+
/// write!(recording, [token("A")])?;
492+
/// write!(recording, [token("B")])?;
493493
///
494-
/// write!(recording, [format_with(|f| write!(f, [text("C"), text("D")]))])?;
494+
/// write!(recording, [format_with(|f| write!(f, [token("C"), token("D")]))])?;
495495
///
496496
/// let recorded = recording.stop();
497497
/// assert_eq!(
498498
/// recorded.deref(),
499499
/// &[
500-
/// FormatElement::StaticText{ text: "A" },
501-
/// FormatElement::StaticText{ text: "B" },
502-
/// FormatElement::StaticText{ text: "C" },
503-
/// FormatElement::StaticText{ text: "D" }
500+
/// FormatElement::Token{ text: "A" },
501+
/// FormatElement::Token{ text: "B" },
502+
/// FormatElement::Token{ text: "C" },
503+
/// FormatElement::Token{ text: "D" }
504504
/// ]
505505
/// );
506506
///

0 commit comments

Comments
 (0)