mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Replace row/column based Location
with byte-offsets. (#3931)
This commit is contained in:
parent
ee91598835
commit
cab65b25da
418 changed files with 6203 additions and 7040 deletions
|
@ -1,11 +1,11 @@
|
|||
use anyhow::Result;
|
||||
use ruff_text_size::{TextLen, TextRange};
|
||||
use rustpython_parser as parser;
|
||||
use rustpython_parser::ast::{Expr, Location};
|
||||
use rustpython_parser::ast::Expr;
|
||||
|
||||
use crate::relocate::relocate_expr;
|
||||
use crate::source_code::Locator;
|
||||
use crate::str;
|
||||
use crate::types::Range;
|
||||
|
||||
#[derive(is_macro::Is, Copy, Clone)]
|
||||
pub enum AnnotationKind {
|
||||
|
@ -24,10 +24,11 @@ pub enum AnnotationKind {
|
|||
/// Parse a type annotation from a string.
|
||||
pub fn parse_type_annotation(
|
||||
value: &str,
|
||||
range: Range,
|
||||
range: TextRange,
|
||||
locator: &Locator,
|
||||
) -> Result<(Expr, AnnotationKind)> {
|
||||
let expression = locator.slice(range);
|
||||
let expression = &locator.contents()[range];
|
||||
|
||||
if str::raw_contents(expression).map_or(false, |body| body == value) {
|
||||
// The annotation is considered "simple" if and only if the raw representation (e.g.,
|
||||
// `List[int]` within "List[int]") exactly matches the parsed representation. This
|
||||
|
@ -37,10 +38,7 @@ pub fn parse_type_annotation(
|
|||
let expr = parser::parse_expression_located(
|
||||
value,
|
||||
"<filename>",
|
||||
Location::new(
|
||||
range.location.row(),
|
||||
range.location.column() + leading_quote.len(),
|
||||
),
|
||||
range.start() + leading_quote.text_len(),
|
||||
)?;
|
||||
Ok((expr, AnnotationKind::Simple))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue