Rename some methods on Locator (#2926)

This commit is contained in:
Charlie Marsh 2023-02-15 10:21:49 -05:00 committed by GitHub
parent 976fe364d4
commit 57a5071b4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 138 additions and 245 deletions

View file

@ -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],
)
}
}