diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-09 13:09:15 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-09 13:09:15 +0000 |
commit | 939ca83b34f9a5648d196f85e5cc7d844ba22604 (patch) | |
tree | a007952a8870e4d8c0b5fa1e0e0a088b399a8c8d /crates/ide/src/syntax_highlighting/injector.rs | |
parent | 625ec9e1ae69168f194cbc5bf20846870f03e149 (diff) | |
parent | 4a8d2c098d88da6f36f3cf95f424b471987c5daa (diff) |
Merge #7216
7216: Highlighting improvements r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src/syntax_highlighting/injector.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting/injector.rs | 12 |
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 | ||