mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-22 04:25:11 +00:00
Rename some methods on Locator
(#2926)
This commit is contained in:
parent
976fe364d4
commit
57a5071b4e
50 changed files with 138 additions and 245 deletions
|
@ -108,46 +108,11 @@ impl<'a> Locator<'a> {
|
|||
self.index.get_or_init(|| index(self.contents))
|
||||
}
|
||||
|
||||
pub fn slice_source_code_until(&self, location: Location) -> &'a str {
|
||||
let index = self.get_or_init_index();
|
||||
let offset = truncate(location, index, self.contents);
|
||||
&self.contents[..offset]
|
||||
}
|
||||
|
||||
pub fn slice_source_code_at(&self, location: Location) -> &'a str {
|
||||
let index = self.get_or_init_index();
|
||||
let offset = truncate(location, index, self.contents);
|
||||
&self.contents[offset..]
|
||||
}
|
||||
|
||||
pub fn slice_source_code_range(&self, range: &Range) -> &'a str {
|
||||
let index = self.get_or_init_index();
|
||||
let start = truncate(range.location, index, self.contents);
|
||||
let end = truncate(range.end_location, index, self.contents);
|
||||
&self.contents[start..end]
|
||||
}
|
||||
|
||||
/// Slice the source code at a [`Range`].
|
||||
pub fn slice(&self, range: Range) -> (Rc<str>, usize, usize) {
|
||||
let index = self.get_or_init_index();
|
||||
let start = truncate(range.location, index, self.contents);
|
||||
let end = truncate(range.end_location, index, self.contents);
|
||||
(Rc::clone(&self.contents_rc), start, end)
|
||||
}
|
||||
|
||||
pub fn partition_source_code_at(
|
||||
&self,
|
||||
outer: &Range,
|
||||
inner: &Range,
|
||||
) -> (&'a str, &'a str, &'a str) {
|
||||
let index = self.get_or_init_index();
|
||||
let outer_start = truncate(outer.location, index, self.contents);
|
||||
let outer_end = truncate(outer.end_location, index, self.contents);
|
||||
let inner_start = truncate(inner.location, index, self.contents);
|
||||
let inner_end = truncate(inner.end_location, index, self.contents);
|
||||
(
|
||||
&self.contents[outer_start..inner_start],
|
||||
&self.contents[inner_start..inner_end],
|
||||
&self.contents[inner_end..outer_end],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue