Experiment with Located trait

This commit is contained in:
Micha Reiser
2024-10-26 12:26:18 +02:00
parent 6aaf1d9446
commit ca4c006f7d
84 changed files with 926 additions and 599 deletions

View File

@@ -8,7 +8,7 @@ use ruff_index::{newtype_index, IndexSlice, IndexVec};
use ruff_python_ast::helpers::extract_handled_exceptions;
use ruff_python_ast::name::QualifiedName;
use ruff_python_ast::{self as ast, Stmt};
use ruff_source_file::Locator;
use ruff_source_file::Located;
use ruff_text_size::{Ranged, TextRange};
use crate::context::ExecutionContext;
@@ -228,8 +228,8 @@ impl<'a> Binding<'a> {
}
/// Returns the name of the binding (e.g., `x` in `x = 1`).
pub fn name<'b>(&self, locator: &Locator<'b>) -> &'b str {
locator.slice(self.range)
pub fn name<'b>(&self, source: &'b str) -> &'b str {
source.slice(self.range)
}
/// Returns the statement in which the binding was defined.

View File

@@ -4,7 +4,7 @@ use bitflags::bitflags;
use ruff_index::{newtype_index, IndexSlice, IndexVec};
use ruff_python_ast::ExprContext;
use ruff_source_file::Locator;
use ruff_source_file::Located;
use ruff_text_size::{Ranged, TextRange};
use crate::scope::ScopeId;
@@ -157,8 +157,8 @@ pub struct UnresolvedReference {
impl UnresolvedReference {
/// Returns the name of the reference.
pub fn name<'a>(&self, locator: &Locator<'a>) -> &'a str {
locator.slice(self.range)
pub fn name<'a>(&self, source: &'a str) -> &'a str {
source.slice(self.range)
}
/// The range of the reference in the source code.