Replace row/column based Location with byte-offsets. (#3931)
This commit is contained in:
@@ -2,37 +2,38 @@ use std::num::TryFromIntError;
|
||||
use std::ops::{Deref, Index, IndexMut};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_python_ast::types::{Range, RefEquality};
|
||||
use ruff_python_ast::types::RefEquality;
|
||||
|
||||
use crate::scope::ScopeId;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Binding<'a> {
|
||||
pub kind: BindingKind<'a>,
|
||||
pub range: Range,
|
||||
pub range: TextRange,
|
||||
/// The context in which the binding was created.
|
||||
pub context: ExecutionContext,
|
||||
/// The statement in which the [`Binding`] was defined.
|
||||
pub source: Option<RefEquality<'a, Stmt>>,
|
||||
/// Tuple of (scope index, range) indicating the scope and range at which
|
||||
/// the binding was last used in a runtime context.
|
||||
pub runtime_usage: Option<(ScopeId, Range)>,
|
||||
pub runtime_usage: Option<(ScopeId, TextRange)>,
|
||||
/// Tuple of (scope index, range) indicating the scope and range at which
|
||||
/// the binding was last used in a typing-time context.
|
||||
pub typing_usage: Option<(ScopeId, Range)>,
|
||||
pub typing_usage: Option<(ScopeId, TextRange)>,
|
||||
/// Tuple of (scope index, range) indicating the scope and range at which
|
||||
/// the binding was last used in a synthetic context. This is used for
|
||||
/// (e.g.) `__future__` imports, explicit re-exports, and other bindings
|
||||
/// that should be considered used even if they're never referenced.
|
||||
pub synthetic_usage: Option<(ScopeId, Range)>,
|
||||
pub synthetic_usage: Option<(ScopeId, TextRange)>,
|
||||
/// The exceptions that were handled when the binding was defined.
|
||||
pub exceptions: Exceptions,
|
||||
}
|
||||
|
||||
impl<'a> Binding<'a> {
|
||||
pub fn mark_used(&mut self, scope: ScopeId, range: Range, context: ExecutionContext) {
|
||||
pub fn mark_used(&mut self, scope: ScopeId, range: TextRange, context: ExecutionContext) {
|
||||
match context {
|
||||
ExecutionContext::Runtime => self.runtime_usage = Some((scope, range)),
|
||||
ExecutionContext::Typing => self.typing_usage = Some((scope, range)),
|
||||
|
||||
Reference in New Issue
Block a user