From fc3fc571d29ccec4a4f80da35d5f77e94c6663c3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 10 Jan 2021 14:36:15 +0300 Subject: Cleaner API --- crates/ide/src/syntax_highlighting/highlights.rs | 12 +++++++----- crates/ide/src/syntax_highlighting/injector.rs | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/highlights.rs b/crates/ide/src/syntax_highlighting/highlights.rs index 11c11ed28..c6f0417ec 100644 --- a/crates/ide/src/syntax_highlighting/highlights.rs +++ b/crates/ide/src/syntax_highlighting/highlights.rs @@ -51,18 +51,20 @@ impl Node { } } - let (start, len) = + let overlapping = equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range)); - if len == 1 && self.nested[start].hl_range.range.contains_range(hl_range.range) { - return self.nested[start].add(hl_range); + if overlapping.len() == 1 + && self.nested[overlapping.start].hl_range.range.contains_range(hl_range.range) + { + return self.nested[overlapping.start].add(hl_range); } let nested = self .nested - .splice(start..start + len, iter::once(Node::new(hl_range))) + .splice(overlapping.clone(), iter::once(Node::new(hl_range))) .collect::>(); - self.nested[start].nested = nested; + self.nested[overlapping.start].nested = nested; } fn flatten(&self, acc: &mut Vec) { diff --git a/crates/ide/src/syntax_highlighting/injector.rs b/crates/ide/src/syntax_highlighting/injector.rs index e8f17eb69..fd4025694 100644 --- a/crates/ide/src/syntax_highlighting/injector.rs +++ b/crates/ide/src/syntax_highlighting/injector.rs @@ -33,8 +33,7 @@ impl Injector { &self.buf } pub(super) fn map_range_up(&self, range: TextRange) -> impl Iterator + '_ { - let (start, len) = equal_range_by(&self.ranges, |&(r, _)| ordering(r, range)); - (start..start + len).filter_map(move |i| { + equal_range_by(&self.ranges, |&(r, _)| ordering(r, range)).filter_map(move |i| { let (target_range, delta) = self.ranges[i]; let intersection = target_range.intersect(range).unwrap(); Some(intersection + delta?) -- cgit v1.2.3