aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-09 12:12:21 +0000
committerAleksey Kladov <[email protected]>2021-01-09 12:12:21 +0000
commit8a0bd500363fd2953c2a469083b00be54c602ebb (patch)
tree8b056772c19af11f41e5b43e73ab0feaf119b395 /crates/ide
parent3dfa2768acdd6bbf0e6999cdc4eb5cf0718b95a4 (diff)
Reduce duplication
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/syntax_highlighting/injector.rs12
1 files changed, 5 insertions, 7 deletions
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 {
17 pub(super) fn add(&mut self, text: &str, source_range: TextRange) { 17 pub(super) fn add(&mut self, text: &str, source_range: TextRange) {
18 let len = TextSize::of(text); 18 let len = TextSize::of(text);
19 assert_eq!(len, source_range.len()); 19 assert_eq!(len, source_range.len());
20 20 self.add_impl(text, Some(source_range.start()));
21 let target_range = TextRange::at(TextSize::of(&self.buf), len);
22 self.ranges
23 .push((target_range, Some(Delta::new(target_range.start(), source_range.start()))));
24 self.buf.push_str(text);
25 } 21 }
26 pub(super) fn add_unmapped(&mut self, text: &str) { 22 pub(super) fn add_unmapped(&mut self, text: &str) {
23 self.add_impl(text, None);
24 }
25 fn add_impl(&mut self, text: &str, source: Option<TextSize>) {
27 let len = TextSize::of(text); 26 let len = TextSize::of(text);
28
29 let target_range = TextRange::at(TextSize::of(&self.buf), len); 27 let target_range = TextRange::at(TextSize::of(&self.buf), len);
30 self.ranges.push((target_range, None)); 28 self.ranges.push((target_range, source.map(|it| Delta::new(target_range.start(), it))));
31 self.buf.push_str(text); 29 self.buf.push_str(text);
32 } 30 }
33 31