mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 03:45:14 +00:00
formatter: Remove CST and old formatting (#4730)
This commit is contained in:
parent
d7a4999915
commit
06bcb85f81
85 changed files with 5335 additions and 13272 deletions
33
crates/ruff_python_formatter/src/module/mod.rs
Normal file
33
crates/ruff_python_formatter/src/module/mod.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use crate::context::ASTFormatContext;
|
||||
use ruff_formatter::format_element::tag::VerbatimKind;
|
||||
use ruff_formatter::prelude::*;
|
||||
use ruff_formatter::write;
|
||||
use rustpython_parser::ast::{Mod, Ranged};
|
||||
|
||||
pub(crate) struct FormatModule<'a> {
|
||||
module: &'a Mod,
|
||||
}
|
||||
|
||||
impl<'a> FormatModule<'a> {
|
||||
pub(crate) fn new(module: &'a Mod) -> Self {
|
||||
Self { module }
|
||||
}
|
||||
}
|
||||
|
||||
impl Format<ASTFormatContext<'_>> for FormatModule<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
|
||||
let range = self.module.range();
|
||||
|
||||
write!(f, [source_position(range.start())])?;
|
||||
|
||||
f.write_element(FormatElement::Tag(Tag::StartVerbatim(
|
||||
VerbatimKind::Verbatim {
|
||||
length: range.len(),
|
||||
},
|
||||
)))?;
|
||||
write!(f, [source_text_slice(range, ContainsNewlines::Detect)])?;
|
||||
f.write_element(FormatElement::Tag(Tag::EndVerbatim))?;
|
||||
|
||||
write!(f, [source_position(range.end())])
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue