mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-21 20:15:11 +00:00
Use dummy verbatim formatter for all nodes (#4755)
This commit is contained in:
parent
59148344be
commit
9bf168c0a4
77 changed files with 330 additions and 309 deletions
|
@ -1,13 +1,15 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::ast::Mod;
|
||||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::{parse_tokens, Mode};
|
||||
|
||||
use ruff_formatter::format_element::tag::VerbatimKind;
|
||||
use ruff_formatter::formatter::Formatter;
|
||||
use ruff_formatter::prelude::source_position;
|
||||
use ruff_formatter::prelude::{source_position, source_text_slice, ContainsNewlines, Tag};
|
||||
use ruff_formatter::{
|
||||
format, write, Buffer, FormatResult, Formatted, IndentStyle, Printed, SimpleFormatOptions,
|
||||
SourceCode,
|
||||
format, write, Buffer, Format, FormatContext, FormatElement, FormatResult, Formatted,
|
||||
IndentStyle, Printed, SimpleFormatOptions, SourceCode,
|
||||
};
|
||||
use ruff_python_ast::node::AstNode;
|
||||
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator};
|
||||
|
@ -134,6 +136,25 @@ pub fn format_node<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
pub(crate) struct VerbatimText(TextRange);
|
||||
|
||||
pub(crate) const fn verbatim_text(range: TextRange) -> VerbatimText {
|
||||
VerbatimText(range)
|
||||
}
|
||||
|
||||
impl<C: FormatContext> Format<C> for VerbatimText {
|
||||
fn fmt(&self, f: &mut Formatter<C>) -> FormatResult<()> {
|
||||
f.write_element(FormatElement::Tag(Tag::StartVerbatim(
|
||||
VerbatimKind::Verbatim {
|
||||
length: self.0.len(),
|
||||
},
|
||||
)))?;
|
||||
write!(f, [source_text_slice(self.0, ContainsNewlines::Detect)])?;
|
||||
f.write_element(FormatElement::Tag(Tag::EndVerbatim))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fmt::{Formatter, Write};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue