Clip points coming from language server
This avoids panicking in Zed if the points they give us are invalid. Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
d12387b753
commit
ce8741977b
2 changed files with 8 additions and 2 deletions
|
@ -570,7 +570,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
|
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
|
||||||
self.visible_text.clip_point(point, bias)
|
self.content().clip_point(point, bias)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize {
|
pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize {
|
||||||
|
@ -1899,6 +1899,10 @@ impl<'a> Content<'a> {
|
||||||
FullOffset(summary.visible + summary.deleted + overshoot)
|
FullOffset(summary.visible + summary.deleted + overshoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
|
||||||
|
self.visible_text.clip_point(point, bias)
|
||||||
|
}
|
||||||
|
|
||||||
fn point_for_offset(&self, offset: usize) -> Result<Point> {
|
fn point_for_offset(&self, offset: usize) -> Result<Point> {
|
||||||
if offset <= self.len() {
|
if offset <= self.len() {
|
||||||
Ok(self.text_summary_for_range(0..offset).lines)
|
Ok(self.text_summary_for_range(0..offset).lines)
|
||||||
|
|
|
@ -711,7 +711,9 @@ impl Buffer {
|
||||||
end = last_edit_new_end + (end - last_edit_old_end);
|
end = last_edit_new_end + (end - last_edit_old_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((start..end, (severity, diagnostic.message)))
|
let range =
|
||||||
|
content.clip_point(start, Bias::Left)..content.clip_point(end, Bias::Right);
|
||||||
|
Some((range, (severity, diagnostic.message)))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue