mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Reduce duplication
This commit is contained in:
parent
3dfa2768ac
commit
8a0bd50036
1 changed files with 5 additions and 7 deletions
|
@ -17,17 +17,15 @@ impl Injector {
|
||||||
pub(super) fn add(&mut self, text: &str, source_range: TextRange) {
|
pub(super) fn add(&mut self, text: &str, source_range: TextRange) {
|
||||||
let len = TextSize::of(text);
|
let len = TextSize::of(text);
|
||||||
assert_eq!(len, source_range.len());
|
assert_eq!(len, source_range.len());
|
||||||
|
self.add_impl(text, Some(source_range.start()));
|
||||||
let target_range = TextRange::at(TextSize::of(&self.buf), len);
|
|
||||||
self.ranges
|
|
||||||
.push((target_range, Some(Delta::new(target_range.start(), source_range.start()))));
|
|
||||||
self.buf.push_str(text);
|
|
||||||
}
|
}
|
||||||
pub(super) fn add_unmapped(&mut self, text: &str) {
|
pub(super) fn add_unmapped(&mut self, text: &str) {
|
||||||
|
self.add_impl(text, None);
|
||||||
|
}
|
||||||
|
fn add_impl(&mut self, text: &str, source: Option<TextSize>) {
|
||||||
let len = TextSize::of(text);
|
let len = TextSize::of(text);
|
||||||
|
|
||||||
let target_range = TextRange::at(TextSize::of(&self.buf), len);
|
let target_range = TextRange::at(TextSize::of(&self.buf), len);
|
||||||
self.ranges.push((target_range, None));
|
self.ranges.push((target_range, source.map(|it| Delta::new(target_range.start(), it))));
|
||||||
self.buf.push_str(text);
|
self.buf.push_str(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue