mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 03:15:44 +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
|
@ -2,7 +2,7 @@ use std::cmp::Ordering;
|
|||
use std::fmt::{Debug, Formatter};
|
||||
use std::sync::Arc;
|
||||
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -56,8 +56,8 @@ impl<'src, 'index> SourceCode<'src, 'index> {
|
|||
}
|
||||
|
||||
/// Take the source code between the given [`TextRange`].
|
||||
pub fn slice(&self, range: TextRange) -> &'src str {
|
||||
&self.text[range]
|
||||
pub fn slice<T: Ranged>(&self, ranged: T) -> &'src str {
|
||||
&self.text[ranged.range()]
|
||||
}
|
||||
|
||||
pub fn line_start(&self, line: OneIndexed) -> TextSize {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue