aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/syntax_highlighting/highlights.rs12
-rw-r--r--crates/ide/src/syntax_highlighting/injector.rs3
-rw-r--r--crates/stdx/src/lib.rs4
3 files changed, 10 insertions, 9 deletions
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 {
51 } 51 }
52 } 52 }
53 53
54 let (start, len) = 54 let overlapping =
55 equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range)); 55 equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range));
56 56
57 if len == 1 && self.nested[start].hl_range.range.contains_range(hl_range.range) { 57 if overlapping.len() == 1
58 return self.nested[start].add(hl_range); 58 && self.nested[overlapping.start].hl_range.range.contains_range(hl_range.range)
59 {
60 return self.nested[overlapping.start].add(hl_range);
59 } 61 }
60 62
61 let nested = self 63 let nested = self
62 .nested 64 .nested
63 .splice(start..start + len, iter::once(Node::new(hl_range))) 65 .splice(overlapping.clone(), iter::once(Node::new(hl_range)))
64 .collect::<Vec<_>>(); 66 .collect::<Vec<_>>();
65 self.nested[start].nested = nested; 67 self.nested[overlapping.start].nested = nested;
66 } 68 }
67 69
68 fn flatten(&self, acc: &mut Vec<HlRange>) { 70 fn flatten(&self, acc: &mut Vec<HlRange>) {
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 {
33 &self.buf 33 &self.buf
34 } 34 }
35 pub(super) fn map_range_up(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ { 35 pub(super) fn map_range_up(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ {
36 let (start, len) = equal_range_by(&self.ranges, |&(r, _)| ordering(r, range)); 36 equal_range_by(&self.ranges, |&(r, _)| ordering(r, range)).filter_map(move |i| {
37 (start..start + len).filter_map(move |i| {
38 let (target_range, delta) = self.ranges[i]; 37 let (target_range, delta) = self.ranges[i];
39 let intersection = target_range.intersect(range).unwrap(); 38 let intersection = target_range.intersect(range).unwrap();
40 Some(intersection + delta?) 39 Some(intersection + delta?)
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 5aacdb16e..13aab1451 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -152,13 +152,13 @@ where
152 left 152 left
153} 153}
154 154
155pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> (usize, usize) 155pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> ops::Range<usize>
156where 156where
157 F: FnMut(&T) -> Ordering, 157 F: FnMut(&T) -> Ordering,
158{ 158{
159 let start = partition_point(slice, |it| key(it) == Ordering::Less); 159 let start = partition_point(slice, |it| key(it) == Ordering::Less);
160 let len = partition_point(&slice[start..], |it| key(it) == Ordering::Equal); 160 let len = partition_point(&slice[start..], |it| key(it) == Ordering::Equal);
161 (start, len) 161 start..start + len
162} 162}
163 163
164pub struct JodChild(pub process::Child); 164pub struct JodChild(pub process::Child);