Fixup compile errors

This commit is contained in:
Julia 2022-11-22 02:49:47 -05:00
parent 8c75df30cb
commit e51cbf67ab
11 changed files with 83 additions and 103 deletions

View file

@ -11,7 +11,7 @@ use language::{
char_kind, AutoindentMode, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, CursorShape,
DiagnosticEntry, Event, File, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Outline,
OutlineItem, Point, PointUtf16, Selection, TextDimension, ToOffset as _, ToOffsetUtf16 as _,
ToPoint as _, ToPointUtf16 as _, TransactionId,
ToPoint as _, ToPointUtf16 as _, TransactionId, Unclipped,
};
use smallvec::SmallVec;
use std::{
@ -72,10 +72,6 @@ pub trait ToOffset: 'static + fmt::Debug {
fn to_offset(&self, snapshot: &MultiBufferSnapshot) -> usize;
}
pub trait ToOffsetClipped: 'static + fmt::Debug {
fn to_offset_clipped(&self, snapshot: &MultiBufferSnapshot) -> usize;
}
pub trait ToOffsetUtf16: 'static + fmt::Debug {
fn to_offset_utf16(&self, snapshot: &MultiBufferSnapshot) -> OffsetUtf16;
}
@ -1753,20 +1749,21 @@ impl MultiBufferSnapshot {
*cursor.start() + overshoot
}
pub fn clip_point_utf16(&self, point: PointUtf16, bias: Bias) -> PointUtf16 {
pub fn clip_point_utf16(&self, point: Unclipped<PointUtf16>, bias: Bias) -> PointUtf16 {
if let Some((_, _, buffer)) = self.as_singleton() {
return buffer.clip_point_utf16(point, bias);
}
let mut cursor = self.excerpts.cursor::<PointUtf16>();
cursor.seek(&point, Bias::Right, &());
//Cannot not panic if out of bounds as it will just not reach the target position
cursor.seek(&point.0, Bias::Right, &());
let overshoot = if let Some(excerpt) = cursor.item() {
let excerpt_start = excerpt
.buffer
.offset_to_point_utf16(excerpt.range.context.start.to_offset(&excerpt.buffer));
let buffer_point = excerpt
.buffer
.clip_point_utf16(excerpt_start + (point - cursor.start()), bias);
.clip_point_utf16(Unclipped(excerpt_start + (point.0 - cursor.start())), bias);
buffer_point.saturating_sub(excerpt_start)
} else {
PointUtf16::zero()
@ -1949,9 +1946,9 @@ impl MultiBufferSnapshot {
}
}
pub fn point_utf16_to_offset_clipped(&self, point: PointUtf16) -> usize {
pub fn point_utf16_to_offset(&self, point: PointUtf16) -> usize {
if let Some((_, _, buffer)) = self.as_singleton() {
return buffer.point_utf16_to_offset_clipped(point);
return buffer.point_utf16_to_offset(point);
}
let mut cursor = self.excerpts.cursor::<(PointUtf16, usize)>();
@ -1965,7 +1962,7 @@ impl MultiBufferSnapshot {
.offset_to_point_utf16(excerpt.range.context.start.to_offset(&excerpt.buffer));
let buffer_offset = excerpt
.buffer
.point_utf16_to_offset_clipped(excerpt_start_point + overshoot);
.point_utf16_to_offset(excerpt_start_point + overshoot);
*start_offset + (buffer_offset - excerpt_start_offset)
} else {
self.excerpts.summary().text.len
@ -3291,9 +3288,9 @@ impl ToOffset for OffsetUtf16 {
}
}
impl ToOffsetClipped for PointUtf16 {
fn to_offset_clipped<'a>(&self, snapshot: &MultiBufferSnapshot) -> usize {
snapshot.point_utf16_to_offset_clipped(*self)
impl ToOffset for PointUtf16 {
fn to_offset<'a>(&self, snapshot: &MultiBufferSnapshot) -> usize {
snapshot.point_utf16_to_offset(*self)
}
}
@ -4162,12 +4159,14 @@ mod tests {
}
for _ in 0..ch.len_utf16() {
let left_point_utf16 = snapshot.clip_point_utf16(point_utf16, Bias::Left);
let right_point_utf16 = snapshot.clip_point_utf16(point_utf16, Bias::Right);
let left_point_utf16 =
snapshot.clip_point_utf16(Unclipped(point_utf16), Bias::Left);
let right_point_utf16 =
snapshot.clip_point_utf16(Unclipped(point_utf16), Bias::Right);
let buffer_left_point_utf16 =
buffer.clip_point_utf16(buffer_point_utf16, Bias::Left);
buffer.clip_point_utf16(Unclipped(buffer_point_utf16), Bias::Left);
let buffer_right_point_utf16 =
buffer.clip_point_utf16(buffer_point_utf16, Bias::Right);
buffer.clip_point_utf16(Unclipped(buffer_point_utf16), Bias::Right);
assert_eq!(
left_point_utf16,
excerpt_start.lines_utf16()