Fix compile errors and get serialization unit test passing
This commit is contained in:
@@ -287,12 +287,12 @@ impl Buffer {
|
||||
file: Option<Box<dyn File>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<Self> {
|
||||
let mut fragments_len = message.fragments.len();
|
||||
let fragments_len = message.fragments.len();
|
||||
let buffer = TextBuffer::from_parts(
|
||||
replica_id,
|
||||
message.id,
|
||||
message.content,
|
||||
message.deleted_content,
|
||||
&message.visible_text,
|
||||
&message.deleted_text,
|
||||
message
|
||||
.undo_map
|
||||
.into_iter()
|
||||
@@ -304,6 +304,8 @@ impl Buffer {
|
||||
.map(|(i, fragment)| {
|
||||
proto::deserialize_buffer_fragment(fragment, i, fragments_len)
|
||||
}),
|
||||
message.lamport_timestamp,
|
||||
From::from(message.version),
|
||||
);
|
||||
let mut this = Self::build(buffer, file);
|
||||
for selection_set in message.selections {
|
||||
@@ -331,14 +333,15 @@ impl Buffer {
|
||||
pub fn to_proto(&self) -> proto::Buffer {
|
||||
proto::Buffer {
|
||||
id: self.remote_id(),
|
||||
content: self.text.text(),
|
||||
deleted_content: self.text.deleted_text(),
|
||||
visible_text: self.text.text(),
|
||||
deleted_text: self.text.deleted_text(),
|
||||
undo_map: self
|
||||
.text
|
||||
.undo_history()
|
||||
.map(proto::serialize_undo_map_entry)
|
||||
.collect(),
|
||||
version: proto::serialize_vector_clock(&self.version),
|
||||
version: From::from(&self.version),
|
||||
lamport_timestamp: self.lamport_clock.value,
|
||||
fragments: self
|
||||
.text
|
||||
.fragments()
|
||||
@@ -1114,6 +1117,8 @@ impl Buffer {
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||
self.remote_selections
|
||||
.insert(self.text.replica_id(), selections.clone());
|
||||
self.send_operation(
|
||||
Operation::UpdateSelections {
|
||||
replica_id: self.text.replica_id(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{diagnostic_set::DiagnosticEntry, Diagnostic, Operation};
|
||||
use anyhow::{anyhow, Result};
|
||||
use clock::ReplicaId;
|
||||
use collections::HashSet;
|
||||
use lsp::DiagnosticSeverity;
|
||||
use rpc::proto;
|
||||
use std::sync::Arc;
|
||||
@@ -124,14 +125,7 @@ pub fn serialize_buffer_fragment(fragment: &text::Fragment) -> proto::BufferFrag
|
||||
timestamp: clock.value,
|
||||
})
|
||||
.collect(),
|
||||
max_undos: fragment
|
||||
.max_undos
|
||||
.iter()
|
||||
.map(|clock| proto::VectorClockEntry {
|
||||
replica_id: clock.replica_id as u32,
|
||||
timestamp: clock.value,
|
||||
})
|
||||
.collect(),
|
||||
max_undos: From::from(&fragment.max_undos),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +319,22 @@ pub fn deserialize_buffer_fragment(
|
||||
ix: usize,
|
||||
count: usize,
|
||||
) -> Fragment {
|
||||
todo!()
|
||||
Fragment {
|
||||
id: locator::Locator::from_index(ix, count),
|
||||
insertion_timestamp: InsertionTimestamp {
|
||||
replica_id: message.replica_id as ReplicaId,
|
||||
local: message.local_timestamp,
|
||||
lamport: message.lamport_timestamp,
|
||||
},
|
||||
insertion_offset: message.insertion_offset as usize,
|
||||
len: message.len as usize,
|
||||
visible: message.visible,
|
||||
deletions: HashSet::from_iter(message.deletions.into_iter().map(|entry| clock::Local {
|
||||
replica_id: entry.replica_id as ReplicaId,
|
||||
value: entry.timestamp,
|
||||
})),
|
||||
max_undos: From::from(message.max_undos),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_selections(selections: Vec<proto::Selection>) -> Arc<[Selection<Anchor>]> {
|
||||
|
||||
Reference in New Issue
Block a user