From 8a0bd500363fd2953c2a469083b00be54c602ebb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Jan 2021 15:12:21 +0300 Subject: Reduce duplication --- crates/ide/src/syntax_highlighting/injector.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting/injector.rs b/crates/ide/src/syntax_highlighting/injector.rs index 0513a9fd6..e8f17eb69 100644 --- a/crates/ide/src/syntax_highlighting/injector.rs +++ b/crates/ide/src/syntax_highlighting/injector.rs @@ -17,17 +17,15 @@ impl Injector { pub(super) fn add(&mut self, text: &str, source_range: TextRange) { let len = TextSize::of(text); assert_eq!(len, source_range.len()); - - 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); + self.add_impl(text, Some(source_range.start())); } pub(super) fn add_unmapped(&mut self, text: &str) { + self.add_impl(text, None); + } + fn add_impl(&mut self, text: &str, source: Option) { let len = TextSize::of(text); - 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); } -- cgit v1.2.3