Implement Ranged on more structs (#6639)

## Summary

I noticed some inconsistencies around uses of `.range.start()`, structs
that have a `TextRange` field but don't implement `Ranged`, etc.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-08-17 11:22:39 -04:00 committed by GitHub
parent a70807e1e1
commit db1c556508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 221 additions and 176 deletions

View file

@ -283,6 +283,12 @@ bitflags! {
}
}
impl Ranged for Binding<'_> {
fn range(&self) -> TextRange {
self.range
}
}
/// ID uniquely identifying a [Binding] in a program.
///
/// Using a `u32` to identify [Binding]s should is sufficient because Ruff only supports documents with a

View file

@ -3,6 +3,7 @@ use ruff_text_size::TextRange;
use std::ops::Deref;
use ruff_index::{newtype_index, IndexSlice, IndexVec};
use ruff_python_ast::Ranged;
use ruff_source_file::Locator;
use crate::context::ExecutionContext;
@ -26,11 +27,6 @@ impl ResolvedReference {
self.scope_id
}
/// The range of the reference in the source code.
pub const fn range(&self) -> TextRange {
self.range
}
/// The [`ExecutionContext`] of the reference.
pub const fn context(&self) -> ExecutionContext {
if self.flags.intersects(SemanticModelFlags::TYPING_CONTEXT) {
@ -41,6 +37,13 @@ impl ResolvedReference {
}
}
impl Ranged for ResolvedReference {
/// The range of the reference in the source code.
fn range(&self) -> TextRange {
self.range
}
}
/// Id uniquely identifying a read reference in a program.
#[newtype_index]
pub struct ResolvedReferenceId;