Remove duplication when assigning diagnostics and hardcode provider names
This commit is contained in:
parent
4f774e2bde
commit
11e3874b4a
8 changed files with 198 additions and 178 deletions
|
@ -205,6 +205,19 @@ impl Rope {
|
|||
.map_or(0, |chunk| chunk.point_utf16_to_offset(overshoot))
|
||||
}
|
||||
|
||||
pub fn point_utf16_to_point(&self, point: PointUtf16) -> Point {
|
||||
if point >= self.summary().lines_utf16 {
|
||||
return self.summary().lines;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<(PointUtf16, Point)>();
|
||||
cursor.seek(&point, Bias::Left, &());
|
||||
let overshoot = point - cursor.start().0;
|
||||
cursor.start().1
|
||||
+ cursor
|
||||
.item()
|
||||
.map_or(Point::zero(), |chunk| chunk.point_utf16_to_point(overshoot))
|
||||
}
|
||||
|
||||
pub fn clip_offset(&self, mut offset: usize, bias: Bias) -> usize {
|
||||
let mut cursor = self.chunks.cursor::<usize>();
|
||||
cursor.seek(&offset, Bias::Left, &());
|
||||
|
@ -583,6 +596,28 @@ impl Chunk {
|
|||
offset
|
||||
}
|
||||
|
||||
fn point_utf16_to_point(&self, target: PointUtf16) -> Point {
|
||||
let mut point = Point::zero();
|
||||
let mut point_utf16 = PointUtf16::zero();
|
||||
for ch in self.0.chars() {
|
||||
if point_utf16 >= target {
|
||||
if point_utf16 > target {
|
||||
panic!("point {:?} is inside of character {:?}", target, ch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ch == '\n' {
|
||||
point_utf16 += PointUtf16::new(1, 0);
|
||||
point += Point::new(1, 0);
|
||||
} else {
|
||||
point_utf16 += PointUtf16::new(0, ch.len_utf16() as u32);
|
||||
point += Point::new(0, ch.len_utf8() as u32);
|
||||
}
|
||||
}
|
||||
point
|
||||
}
|
||||
|
||||
fn clip_point(&self, target: Point, bias: Bias) -> Point {
|
||||
for (row, line) in self.0.split('\n').enumerate() {
|
||||
if row == target.row as usize {
|
||||
|
|
|
@ -1307,6 +1307,10 @@ impl BufferSnapshot {
|
|||
self.visible_text.point_utf16_to_offset(point)
|
||||
}
|
||||
|
||||
pub fn point_utf16_to_point(&self, point: PointUtf16) -> Point {
|
||||
self.visible_text.point_utf16_to_point(point)
|
||||
}
|
||||
|
||||
pub fn offset_to_point(&self, offset: usize) -> Point {
|
||||
self.visible_text.offset_to_point(offset)
|
||||
}
|
||||
|
@ -2045,12 +2049,40 @@ impl ToPoint for usize {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPoint for PointUtf16 {
|
||||
fn to_point<'a>(&self, snapshot: &BufferSnapshot) -> Point {
|
||||
snapshot.point_utf16_to_point(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToPoint for Point {
|
||||
fn to_point<'a>(&self, _: &BufferSnapshot) -> Point {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Clip {
|
||||
fn clip(&self, bias: Bias, snapshot: &BufferSnapshot) -> Self;
|
||||
}
|
||||
|
||||
impl Clip for usize {
|
||||
fn clip(&self, bias: Bias, snapshot: &BufferSnapshot) -> Self {
|
||||
snapshot.clip_offset(*self, bias)
|
||||
}
|
||||
}
|
||||
|
||||
impl Clip for Point {
|
||||
fn clip(&self, bias: Bias, snapshot: &BufferSnapshot) -> Self {
|
||||
snapshot.clip_point(*self, bias)
|
||||
}
|
||||
}
|
||||
|
||||
impl Clip for PointUtf16 {
|
||||
fn clip(&self, bias: Bias, snapshot: &BufferSnapshot) -> Self {
|
||||
snapshot.clip_point_utf16(*self, bias)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FromAnchor {
|
||||
fn from_anchor(anchor: &Anchor, snapshot: &BufferSnapshot) -> Self;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue