mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-14 14:11:34 +00:00
Clip diagnostic range before and during empty range expansion
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
e51cbf67ab
commit
b58ae8bdd7
3 changed files with 10 additions and 7 deletions
|
@ -1337,7 +1337,7 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
|
||||||
(0..entry_count).map(|_| {
|
(0..entry_count).map(|_| {
|
||||||
let range = buffer.random_byte_range(0, &mut rng);
|
let range = buffer.random_byte_range(0, &mut rng);
|
||||||
let range = range.to_point_utf16(buffer);
|
let range = range.to_point_utf16(buffer);
|
||||||
let range = Unclipped(range.start)..Unclipped(range.end);
|
let range = range.start..range.end;
|
||||||
DiagnosticEntry {
|
DiagnosticEntry {
|
||||||
range,
|
range,
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
ops::Range,
|
ops::Range,
|
||||||
};
|
};
|
||||||
use sum_tree::{self, Bias, SumTree};
|
use sum_tree::{self, Bias, SumTree};
|
||||||
use text::{Anchor, FromAnchor, PointUtf16, ToOffset, Unclipped};
|
use text::{Anchor, FromAnchor, PointUtf16, ToOffset};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct DiagnosticSet {
|
pub struct DiagnosticSet {
|
||||||
|
@ -63,7 +63,7 @@ impl DiagnosticSet {
|
||||||
|
|
||||||
pub fn new<I>(iter: I, buffer: &text::BufferSnapshot) -> Self
|
pub fn new<I>(iter: I, buffer: &text::BufferSnapshot) -> Self
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = DiagnosticEntry<Unclipped<PointUtf16>>>,
|
I: IntoIterator<Item = DiagnosticEntry<PointUtf16>>,
|
||||||
{
|
{
|
||||||
let mut entries = iter.into_iter().collect::<Vec<_>>();
|
let mut entries = iter.into_iter().collect::<Vec<_>>();
|
||||||
entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end)));
|
entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end)));
|
||||||
|
|
|
@ -2677,14 +2677,17 @@ impl Project {
|
||||||
end = entry.range.end;
|
end = entry.range.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut range = start..end;
|
let mut range = snapshot.clip_point_utf16(start, Bias::Left)
|
||||||
|
..snapshot.clip_point_utf16(end, Bias::Right);
|
||||||
|
|
||||||
// Expand empty ranges by one codepoint
|
// Expand empty ranges by one codepoint
|
||||||
if range.start == range.end {
|
if range.start == range.end {
|
||||||
// This will be go to the next boundary when being clipped
|
// This will be go to the next boundary when being clipped
|
||||||
range.end.0.column += 1;
|
range.end.column += 1;
|
||||||
if range.start == range.end && range.end.0.column > 0 {
|
range.end = snapshot.clip_point_utf16(Unclipped(range.end), Bias::Right);
|
||||||
range.start.0.column -= 1;
|
if range.start == range.end && range.end.column > 0 {
|
||||||
|
range.start.column -= 1;
|
||||||
|
range.end = snapshot.clip_point_utf16(Unclipped(range.end), Bias::Left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue