Remove copied core modules from ruff_python_formatter (#3371)

This commit is contained in:
Charlie Marsh 2023-03-08 14:03:40 -05:00 committed by GitHub
parent 130e733023
commit 0a9d259f9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 105 additions and 273 deletions

View file

@ -1,9 +1,9 @@
use ruff_formatter::prelude::*;
use ruff_formatter::{write, Format};
use ruff_python_ast::types::Range;
use ruff_text_size::{TextRange, TextSize};
use crate::context::ASTFormatContext;
use crate::core::types::Range;
use crate::cst::{Body, Stmt};
use crate::shared_traits::AsFormat;
use crate::trivia::{Relationship, TriviaKind};
@ -73,10 +73,17 @@ pub struct Literal {
impl Format<ASTFormatContext<'_>> for Literal {
fn fmt(&self, f: &mut Formatter<ASTFormatContext<'_>>) -> FormatResult<()> {
let (text, start, end) = f.context().locator().slice(self.range);
let text = f.context().contents();
let locator = f.context().locator();
let start_index = locator.offset(self.range.location);
let end_index = locator.offset(self.range.end_location);
f.write_element(FormatElement::StaticTextSlice {
text,
range: TextRange::new(start.try_into().unwrap(), end.try_into().unwrap()),
range: TextRange::new(
start_index.try_into().unwrap(),
end_index.try_into().unwrap(),
),
})
}
}