Extract LineIndex independent methods from Locator (#13938)

This commit is contained in:
Micha Reiser 2024-10-28 08:53:41 +01:00 committed by GitHub
parent f8eb547fb4
commit 9f3a38d408
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
171 changed files with 1348 additions and 1284 deletions

View file

@ -7,7 +7,7 @@ use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::Stmt;
use ruff_python_parser::{self as parser, TokenKind};
use ruff_python_trivia::lines_before;
use ruff_source_file::Locator;
use ruff_source_file::LineRanges;
use ruff_text_size::{Ranged, TextRange, TextSize};
use crate::comments::format::{empty_lines, format_comment};
@ -647,7 +647,7 @@ struct Indentation(u32);
impl Indentation {
fn from_stmt(stmt: &Stmt, source: &str) -> Indentation {
let line_start = Locator::new(source).line_start(stmt.start());
let line_start = source.line_start(stmt.start());
let mut indentation = 0u32;
for c in source[TextRange::new(line_start, stmt.start())].chars() {
@ -878,7 +878,7 @@ impl Format<PyFormatContext<'_>> for VerbatimText {
},
)));
match normalize_newlines(f.context().locator().slice(self.verbatim_range), ['\r']) {
match normalize_newlines(&f.context().source()[self.verbatim_range], ['\r']) {
Cow::Borrowed(_) => {
write!(f, [source_text_slice(self.verbatim_range)])?;
}