Wrap a bunch of traits for Unclipped<T>
This commit is contained in:
parent
1c84e77c37
commit
8c75df30cb
5 changed files with 81 additions and 13 deletions
|
@ -1337,6 +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);
|
||||||
DiagnosticEntry {
|
DiagnosticEntry {
|
||||||
range,
|
range,
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
|
|
|
@ -131,9 +131,7 @@ impl LspCommand for PrepareRename {
|
||||||
if buffer.clip_point_utf16(start, Bias::Left) == start.0
|
if buffer.clip_point_utf16(start, Bias::Left) == start.0
|
||||||
&& buffer.clip_point_utf16(end, Bias::Left) == end.0
|
&& buffer.clip_point_utf16(end, Bias::Left) == end.0
|
||||||
{
|
{
|
||||||
return Ok(Some(
|
return Ok(Some(buffer.anchor_after(start)..buffer.anchor_before(end)));
|
||||||
buffer.anchor_after(start)..buffer.anchor_before(end),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -884,8 +882,7 @@ impl LspCommand for GetDocumentHighlights {
|
||||||
let end = buffer
|
let end = buffer
|
||||||
.clip_point_utf16(point_from_lsp(lsp_highlight.range.end), Bias::Left);
|
.clip_point_utf16(point_from_lsp(lsp_highlight.range.end), Bias::Left);
|
||||||
DocumentHighlight {
|
DocumentHighlight {
|
||||||
range: buffer.anchor_after(start)
|
range: buffer.anchor_after(start)..buffer.anchor_before(end),
|
||||||
..buffer.anchor_before(end),
|
|
||||||
kind: lsp_highlight
|
kind: lsp_highlight
|
||||||
.kind
|
.kind
|
||||||
.unwrap_or(lsp::DocumentHighlightKind::READ),
|
.unwrap_or(lsp::DocumentHighlightKind::READ),
|
||||||
|
@ -1020,8 +1017,7 @@ impl LspCommand for GetHover {
|
||||||
let token_start =
|
let token_start =
|
||||||
buffer.clip_point_utf16(point_from_lsp(range.start), Bias::Left);
|
buffer.clip_point_utf16(point_from_lsp(range.start), Bias::Left);
|
||||||
let token_end = buffer.clip_point_utf16(point_from_lsp(range.end), Bias::Left);
|
let token_end = buffer.clip_point_utf16(point_from_lsp(range.end), Bias::Left);
|
||||||
buffer.anchor_after(token_start)
|
buffer.anchor_after(token_start)..buffer.anchor_before(token_end)
|
||||||
..buffer.anchor_before(token_end)
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ use language::{
|
||||||
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CharKind, CodeAction,
|
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CharKind, CodeAction,
|
||||||
CodeLabel, Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Event as BufferEvent,
|
CodeLabel, Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Event as BufferEvent,
|
||||||
File as _, Language, LanguageRegistry, LanguageServerName, LocalFile, OffsetRangeExt,
|
File as _, Language, LanguageRegistry, LanguageServerName, LocalFile, OffsetRangeExt,
|
||||||
Operation, Patch, PointUtf16, TextBufferSnapshot, ToOffset, ToPointUtf16,
|
Operation, Patch, PointUtf16, TextBufferSnapshot, ToOffset, ToPointUtf16, Transaction,
|
||||||
Transaction, Unclipped,
|
Unclipped,
|
||||||
};
|
};
|
||||||
use lsp::{
|
use lsp::{
|
||||||
DiagnosticSeverity, DiagnosticTag, DocumentHighlightKind, LanguageServer, LanguageString,
|
DiagnosticSeverity, DiagnosticTag, DocumentHighlightKind, LanguageServer, LanguageString,
|
||||||
|
@ -2660,7 +2660,7 @@ impl Project {
|
||||||
let mut sanitized_diagnostics = Vec::new();
|
let mut sanitized_diagnostics = Vec::new();
|
||||||
let edits_since_save = Patch::new(
|
let edits_since_save = Patch::new(
|
||||||
snapshot
|
snapshot
|
||||||
.edits_since::<PointUtf16>(buffer.read(cx).saved_version())
|
.edits_since::<Unclipped<PointUtf16>>(buffer.read(cx).saved_version())
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
for entry in diagnostics {
|
for entry in diagnostics {
|
||||||
|
|
|
@ -500,7 +500,10 @@ impl LocalWorktree {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diagnostics_for_path(&self, path: &Path) -> Option<Vec<DiagnosticEntry<Unclipped<PointUtf16>>>> {
|
pub fn diagnostics_for_path(
|
||||||
|
&self,
|
||||||
|
path: &Path,
|
||||||
|
) -> Option<Vec<DiagnosticEntry<Unclipped<PointUtf16>>>> {
|
||||||
self.diagnostics.get(path).cloned()
|
self.diagnostics.get(path).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,11 @@ mod point_utf16;
|
||||||
use arrayvec::ArrayString;
|
use arrayvec::ArrayString;
|
||||||
use bromberg_sl2::{DigestString, HashMatrix};
|
use bromberg_sl2::{DigestString, HashMatrix};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{cmp, fmt, io, mem, ops::Range, str};
|
use std::{
|
||||||
|
cmp, fmt, io, mem,
|
||||||
|
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
||||||
|
str,
|
||||||
|
};
|
||||||
use sum_tree::{Bias, Dimension, SumTree};
|
use sum_tree::{Bias, Dimension, SumTree};
|
||||||
|
|
||||||
pub use offset_utf16::OffsetUtf16;
|
pub use offset_utf16::OffsetUtf16;
|
||||||
|
@ -15,6 +19,70 @@ pub use point_utf16::PointUtf16;
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Unclipped<T>(pub T);
|
pub struct Unclipped<T>(pub T);
|
||||||
|
|
||||||
|
impl<T: std::fmt::Debug> std::fmt::Debug for Unclipped<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_tuple("Unclipped").field(&self.0).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Default> Default for Unclipped<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Unclipped(T::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<T> for Unclipped<T> {
|
||||||
|
fn from(value: T) -> Self {
|
||||||
|
Unclipped(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: sum_tree::Dimension<'a, ChunkSummary>> sum_tree::Dimension<'a, ChunkSummary>
|
||||||
|
for Unclipped<T>
|
||||||
|
{
|
||||||
|
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||||
|
self.0.add_summary(summary, &());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: TextDimension> TextDimension for Unclipped<T> {
|
||||||
|
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||||
|
Unclipped(T::from_text_summary(summary))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_assign(&mut self, other: &Self) {
|
||||||
|
TextDimension::add_assign(&mut self.0, &other.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Add<T, Output = T>> Add<Unclipped<T>> for Unclipped<T> {
|
||||||
|
type Output = Unclipped<T>;
|
||||||
|
|
||||||
|
fn add(self, rhs: Unclipped<T>) -> Self::Output {
|
||||||
|
Unclipped(self.0 + rhs.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Sub<T, Output = T>> Sub<Unclipped<T>> for Unclipped<T> {
|
||||||
|
type Output = Unclipped<T>;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Unclipped<T>) -> Self::Output {
|
||||||
|
Unclipped(self.0 - rhs.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AddAssign<T>> AddAssign<Unclipped<T>> for Unclipped<T> {
|
||||||
|
fn add_assign(&mut self, rhs: Unclipped<T>) {
|
||||||
|
self.0 += rhs.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: SubAssign<T>> SubAssign<Unclipped<T>> for Unclipped<T> {
|
||||||
|
fn sub_assign(&mut self, rhs: Unclipped<T>) {
|
||||||
|
self.0 -= rhs.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
const CHUNK_BASE: usize = 6;
|
const CHUNK_BASE: usize = 6;
|
||||||
|
|
||||||
|
@ -945,7 +1013,7 @@ impl std::ops::Add<Self> for TextSummary {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn add(mut self, rhs: Self) -> Self::Output {
|
fn add(mut self, rhs: Self) -> Self::Output {
|
||||||
self.add_assign(&rhs);
|
AddAssign::add_assign(&mut self, &rhs);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue