mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
Allow Locator#slice
to take Ranged
(#6922)
## Summary As a small quality-of-life improvement, the locator can now slice like `locator.slice(stmt)` instead of requiring `locator.slice(stmt.range())`. ## Test Plan `cargo test`
This commit is contained in:
parent
58f5f27dc3
commit
aea7500c1e
42 changed files with 89 additions and 96 deletions
|
@ -4,7 +4,7 @@ use std::ops::Add;
|
|||
|
||||
use memchr::{memchr2, memrchr2};
|
||||
use once_cell::unsync::OnceCell;
|
||||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::newlines::find_newline;
|
||||
use crate::{LineIndex, OneIndexed, SourceCode, SourceLocation};
|
||||
|
@ -390,8 +390,8 @@ impl<'a> Locator<'a> {
|
|||
|
||||
/// Take the source code between the given [`TextRange`].
|
||||
#[inline]
|
||||
pub fn slice(&self, range: TextRange) -> &'a str {
|
||||
&self.contents[range]
|
||||
pub fn slice<T: Ranged>(&self, ranged: T) -> &'a str {
|
||||
&self.contents[ranged.range()]
|
||||
}
|
||||
|
||||
/// Return the underlying source code.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue