Start fixing compilation errors on Editor

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2021-10-28 19:36:43 +02:00
parent 1a92a19954
commit 9c74be3bf2
4 changed files with 117 additions and 114 deletions

View file

@ -87,6 +87,16 @@ impl Anchor {
}
impl<T> AnchorMap<T> {
pub fn offsets<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,
) -> impl Iterator<Item = (usize, &'a T)> + 'a {
let content = content.into();
content
.summaries_for_anchors(self)
.map(move |(sum, value)| (sum.bytes, value))
}
pub fn points<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,
@ -103,6 +113,13 @@ impl<T> AnchorMap<T> {
}
impl AnchorSet {
pub fn offsets<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,
) -> impl Iterator<Item = usize> + 'a {
self.0.offsets(content).map(move |(offset, _)| offset)
}
pub fn points<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,
@ -120,6 +137,10 @@ impl<T> AnchorRangeMap<T> {
&self.entries
}
pub fn len(&self) -> usize {
self.entries.len()
}
pub fn point_ranges<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,
@ -165,6 +186,17 @@ impl<T: Debug> Debug for AnchorRangeMap<T> {
}
impl AnchorRangeSet {
pub fn len(&self) -> usize {
self.0.len()
}
pub fn to_offset_ranges<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,
) -> impl Iterator<Item = Range<usize>> + 'a {
self.0.offset_ranges(content).map(|(range, _)| range)
}
pub fn to_point_ranges<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,

View file

@ -539,6 +539,13 @@ impl Buffer {
self.content().anchor_at(position, bias)
}
pub fn anchor_range_set<E>(&self, entries: E) -> AnchorRangeSet
where
E: IntoIterator<Item = Range<(usize, Bias)>>,
{
self.content().anchor_range_set(entries)
}
pub fn point_for_offset(&self, offset: usize) -> Result<Point> {
self.content().point_for_offset(offset)
}
@ -2264,19 +2271,6 @@ impl<'a> Into<proto::operation::Edit> for &'a EditOperation {
}
}
impl<'a> Into<proto::Anchor> for &'a Anchor {
fn into(self) -> proto::Anchor {
proto::Anchor {
version: (&self.version).into(),
offset: self.offset as u64,
bias: match self.bias {
Bias::Left => proto::anchor::Bias::Left as i32,
Bias::Right => proto::anchor::Bias::Right as i32,
},
}
}
}
impl TryFrom<proto::Operation> for Operation {
type Error = anyhow::Error;
@ -2397,32 +2391,6 @@ impl From<proto::operation::Edit> for EditOperation {
}
}
impl TryFrom<proto::Anchor> for Anchor {
type Error = anyhow::Error;
fn try_from(message: proto::Anchor) -> Result<Self, Self::Error> {
let mut version = clock::Global::new();
for entry in message.version {
version.observe(clock::Local {
replica_id: entry.replica_id as ReplicaId,
value: entry.timestamp,
});
}
Ok(Self {
offset: message.offset as usize,
bias: if message.bias == proto::anchor::Bias::Left as i32 {
Bias::Left
} else if message.bias == proto::anchor::Bias::Right as i32 {
Bias::Right
} else {
Err(anyhow!("invalid anchor bias {}", message.bias))?
},
version,
})
}
}
pub trait ToOffset {
fn to_offset<'a>(&self, content: impl Into<Content<'a>>) -> usize;
}

View file

@ -91,6 +91,10 @@ impl<T: ToOffset + ToPoint + Copy + Ord> Selection<T> {
}
impl SelectionSet {
pub fn len(&self) -> usize {
self.selections.len()
}
pub fn offset_selections<'a>(
&'a self,
content: impl Into<Content<'a>> + 'a,