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:
Antonio Scandurra 2021-10-28 19:02:26 +02:00
parent d12387b753
commit ce8741977b
2 changed files with 8 additions and 2 deletions

View file

@ -570,7 +570,7 @@ impl Buffer {
}
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 {
@ -1899,6 +1899,10 @@ impl<'a> Content<'a> {
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> {
if offset <= self.len() {
Ok(self.text_summary_for_range(0..offset).lines)