formatter: Remove CST and old formatting (#4730)

This commit is contained in:
Micha Reiser 2023-05-31 08:27:23 +02:00 committed by GitHub
parent d7a4999915
commit 06bcb85f81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
85 changed files with 5335 additions and 13272 deletions

View 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())])
}
}