Move protobuf logic from buffer crate to language crate
This will enable us to add operations that only pertain to the language crate. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
78d97a3db2
commit
40c861c249
7 changed files with 322 additions and 338 deletions
|
@ -1,7 +1,5 @@
|
|||
use super::{AnchorRangeMap, Buffer, Content, FullOffset, Point, ToOffset, ToPoint};
|
||||
use rpc::proto;
|
||||
use super::{AnchorRangeMap, Buffer, Content, Point, ToOffset, ToPoint};
|
||||
use std::{cmp::Ordering, ops::Range, sync::Arc};
|
||||
use sum_tree::Bias;
|
||||
|
||||
pub type SelectionSetId = clock::Lamport;
|
||||
pub type SelectionsVersion = usize;
|
||||
|
@ -129,53 +127,3 @@ impl SelectionSet {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<proto::SelectionSet> for &'a SelectionSet {
|
||||
fn into(self) -> proto::SelectionSet {
|
||||
let version = self.selections.version();
|
||||
let entries = self.selections.raw_entries();
|
||||
proto::SelectionSet {
|
||||
replica_id: self.id.replica_id as u32,
|
||||
lamport_timestamp: self.id.value as u32,
|
||||
is_active: self.active,
|
||||
version: version.into(),
|
||||
selections: entries
|
||||
.iter()
|
||||
.map(|(range, state)| proto::Selection {
|
||||
id: state.id as u64,
|
||||
start: range.start.0.to_proto(),
|
||||
end: range.end.0.to_proto(),
|
||||
reversed: state.reversed,
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<proto::SelectionSet> for SelectionSet {
|
||||
fn from(set: proto::SelectionSet) -> Self {
|
||||
Self {
|
||||
id: clock::Lamport {
|
||||
replica_id: set.replica_id as u16,
|
||||
value: set.lamport_timestamp,
|
||||
},
|
||||
active: set.is_active,
|
||||
selections: Arc::new(AnchorRangeMap::from_raw(
|
||||
set.version.into(),
|
||||
set.selections
|
||||
.into_iter()
|
||||
.map(|selection| {
|
||||
let range = (FullOffset::from_proto(selection.start), Bias::Left)
|
||||
..(FullOffset::from_proto(selection.end), Bias::Right);
|
||||
let state = SelectionState {
|
||||
id: selection.id as usize,
|
||||
reversed: selection.reversed,
|
||||
goal: SelectionGoal::None,
|
||||
};
|
||||
(range, state)
|
||||
})
|
||||
.collect(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue