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:
Charlie Marsh 2023-08-28 11:08:39 -04:00 committed by GitHub
parent 58f5f27dc3
commit aea7500c1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 89 additions and 96 deletions

View file

@ -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 {