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>>,
|
file: Option<Box<dyn File>>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut fragments_len = message.fragments.len();
|
let fragments_len = message.fragments.len();
|
||||||
let buffer = TextBuffer::from_parts(
|
let buffer = TextBuffer::from_parts(
|
||||||
replica_id,
|
replica_id,
|
||||||
message.id,
|
message.id,
|
||||||
message.content,
|
&message.visible_text,
|
||||||
message.deleted_content,
|
&message.deleted_text,
|
||||||
message
|
message
|
||||||
.undo_map
|
.undo_map
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -304,6 +304,8 @@ impl Buffer {
|
|||||||
.map(|(i, fragment)| {
|
.map(|(i, fragment)| {
|
||||||
proto::deserialize_buffer_fragment(fragment, i, fragments_len)
|
proto::deserialize_buffer_fragment(fragment, i, fragments_len)
|
||||||
}),
|
}),
|
||||||
|
message.lamport_timestamp,
|
||||||
|
From::from(message.version),
|
||||||
);
|
);
|
||||||
let mut this = Self::build(buffer, file);
|
let mut this = Self::build(buffer, file);
|
||||||
for selection_set in message.selections {
|
for selection_set in message.selections {
|
||||||
@@ -331,14 +333,15 @@ impl Buffer {
|
|||||||
pub fn to_proto(&self) -> proto::Buffer {
|
pub fn to_proto(&self) -> proto::Buffer {
|
||||||
proto::Buffer {
|
proto::Buffer {
|
||||||
id: self.remote_id(),
|
id: self.remote_id(),
|
||||||
content: self.text.text(),
|
visible_text: self.text.text(),
|
||||||
deleted_content: self.text.deleted_text(),
|
deleted_text: self.text.deleted_text(),
|
||||||
undo_map: self
|
undo_map: self
|
||||||
.text
|
.text
|
||||||
.undo_history()
|
.undo_history()
|
||||||
.map(proto::serialize_undo_map_entry)
|
.map(proto::serialize_undo_map_entry)
|
||||||
.collect(),
|
.collect(),
|
||||||
version: proto::serialize_vector_clock(&self.version),
|
version: From::from(&self.version),
|
||||||
|
lamport_timestamp: self.lamport_clock.value,
|
||||||
fragments: self
|
fragments: self
|
||||||
.text
|
.text
|
||||||
.fragments()
|
.fragments()
|
||||||
@@ -1114,6 +1117,8 @@ impl Buffer {
|
|||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||||
|
self.remote_selections
|
||||||
|
.insert(self.text.replica_id(), selections.clone());
|
||||||
self.send_operation(
|
self.send_operation(
|
||||||
Operation::UpdateSelections {
|
Operation::UpdateSelections {
|
||||||
replica_id: self.text.replica_id(),
|
replica_id: self.text.replica_id(),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::{diagnostic_set::DiagnosticEntry, Diagnostic, Operation};
|
use crate::{diagnostic_set::DiagnosticEntry, Diagnostic, Operation};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
|
use collections::HashSet;
|
||||||
use lsp::DiagnosticSeverity;
|
use lsp::DiagnosticSeverity;
|
||||||
use rpc::proto;
|
use rpc::proto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -124,14 +125,7 @@ pub fn serialize_buffer_fragment(fragment: &text::Fragment) -> proto::BufferFrag
|
|||||||
timestamp: clock.value,
|
timestamp: clock.value,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
max_undos: fragment
|
max_undos: From::from(&fragment.max_undos),
|
||||||
.max_undos
|
|
||||||
.iter()
|
|
||||||
.map(|clock| proto::VectorClockEntry {
|
|
||||||
replica_id: clock.replica_id as u32,
|
|
||||||
timestamp: clock.value,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +319,22 @@ pub fn deserialize_buffer_fragment(
|
|||||||
ix: usize,
|
ix: usize,
|
||||||
count: usize,
|
count: usize,
|
||||||
) -> Fragment {
|
) -> 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>]> {
|
pub fn deserialize_selections(selections: Vec<proto::Selection>) -> Arc<[Selection<Anchor>]> {
|
||||||
|
|||||||
@@ -262,13 +262,14 @@ message Entry {
|
|||||||
|
|
||||||
message Buffer {
|
message Buffer {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
string content = 2;
|
string visible_text = 2;
|
||||||
string deleted_content = 3;
|
string deleted_text = 3;
|
||||||
repeated BufferFragment fragments = 4;
|
repeated BufferFragment fragments = 4;
|
||||||
repeated UndoMapEntry undo_map = 5;
|
repeated UndoMapEntry undo_map = 5;
|
||||||
repeated VectorClockEntry version = 6;
|
repeated VectorClockEntry version = 6;
|
||||||
repeated SelectionSet selections = 7;
|
repeated SelectionSet selections = 7;
|
||||||
repeated DiagnosticSet diagnostic_sets = 8;
|
repeated DiagnosticSet diagnostic_sets = 8;
|
||||||
|
uint32 lamport_timestamp = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message BufferFragment {
|
message BufferFragment {
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ mod tests {
|
|||||||
proto::OpenBufferResponse {
|
proto::OpenBufferResponse {
|
||||||
buffer: Some(proto::Buffer {
|
buffer: Some(proto::Buffer {
|
||||||
id: 101,
|
id: 101,
|
||||||
content: "path/one content".to_string(),
|
visible_text: "path/one content".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,7 @@ mod tests {
|
|||||||
proto::OpenBufferResponse {
|
proto::OpenBufferResponse {
|
||||||
buffer: Some(proto::Buffer {
|
buffer: Some(proto::Buffer {
|
||||||
id: 102,
|
id: 102,
|
||||||
content: "path/two content".to_string(),
|
visible_text: "path/two content".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@@ -448,7 +448,7 @@ mod tests {
|
|||||||
proto::OpenBufferResponse {
|
proto::OpenBufferResponse {
|
||||||
buffer: Some(proto::Buffer {
|
buffer: Some(proto::Buffer {
|
||||||
id: 101,
|
id: 101,
|
||||||
content: "path/one content".to_string(),
|
visible_text: "path/one content".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ mod tests {
|
|||||||
proto::OpenBufferResponse {
|
proto::OpenBufferResponse {
|
||||||
buffer: Some(proto::Buffer {
|
buffer: Some(proto::Buffer {
|
||||||
id: 102,
|
id: 102,
|
||||||
content: "path/two content".to_string(),
|
visible_text: "path/two content".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ impl Locator {
|
|||||||
Self(smallvec![u64::MAX])
|
Self(smallvec![u64::MAX])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_index(ix: usize, count: usize) -> Self {
|
||||||
|
let id = ((ix as u128 * u64::MAX as u128) / count as u128) as u64;
|
||||||
|
Self(smallvec![id])
|
||||||
|
}
|
||||||
|
|
||||||
pub fn assign(&mut self, other: &Self) {
|
pub fn assign(&mut self, other: &Self) {
|
||||||
self.0.resize(other.0.len(), 0);
|
self.0.resize(other.0.len(), 0);
|
||||||
self.0.copy_from_slice(&other.0);
|
self.0.copy_from_slice(&other.0);
|
||||||
|
|||||||
+29
-25
@@ -42,7 +42,6 @@ pub type TransactionId = usize;
|
|||||||
|
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
snapshot: BufferSnapshot,
|
snapshot: BufferSnapshot,
|
||||||
last_edit: clock::Local,
|
|
||||||
history: History,
|
history: History,
|
||||||
deferred_ops: OperationQueue<Operation>,
|
deferred_ops: OperationQueue<Operation>,
|
||||||
deferred_replicas: HashSet<ReplicaId>,
|
deferred_replicas: HashSet<ReplicaId>,
|
||||||
@@ -385,7 +384,7 @@ impl InsertionTimestamp {
|
|||||||
|
|
||||||
#[derive(Eq, PartialEq, Clone, Debug)]
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||||
pub struct Fragment {
|
pub struct Fragment {
|
||||||
id: Locator,
|
pub id: Locator,
|
||||||
pub insertion_timestamp: InsertionTimestamp,
|
pub insertion_timestamp: InsertionTimestamp,
|
||||||
pub insertion_offset: usize,
|
pub insertion_offset: usize,
|
||||||
pub len: usize,
|
pub len: usize,
|
||||||
@@ -496,7 +495,6 @@ impl Buffer {
|
|||||||
version,
|
version,
|
||||||
undo_map: Default::default(),
|
undo_map: Default::default(),
|
||||||
},
|
},
|
||||||
last_edit: clock::Local::default(),
|
|
||||||
history,
|
history,
|
||||||
deferred_ops: OperationQueue::new(),
|
deferred_ops: OperationQueue::new(),
|
||||||
deferred_replicas: HashSet::default(),
|
deferred_replicas: HashSet::default(),
|
||||||
@@ -515,30 +513,46 @@ impl Buffer {
|
|||||||
deleted_text: &str,
|
deleted_text: &str,
|
||||||
undo_map: impl Iterator<Item = (clock::Local, Vec<(clock::Local, u32)>)>,
|
undo_map: impl Iterator<Item = (clock::Local, Vec<(clock::Local, u32)>)>,
|
||||||
fragments: impl ExactSizeIterator<Item = Fragment>,
|
fragments: impl ExactSizeIterator<Item = Fragment>,
|
||||||
|
lamport_timestamp: u32,
|
||||||
|
version: clock::Global,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let visible_text = visible_text.into();
|
let visible_text = visible_text.into();
|
||||||
let deleted_text = deleted_text.into();
|
let deleted_text = deleted_text.into();
|
||||||
let fragments = SumTree::from_iter(fragments, &None);
|
let fragments = SumTree::from_iter(fragments, &None);
|
||||||
let undo_map = UndoMap(undo_map.collect());
|
let mut insertions = fragments
|
||||||
|
.iter()
|
||||||
|
.map(|fragment| InsertionFragment {
|
||||||
|
timestamp: fragment.insertion_timestamp.local(),
|
||||||
|
split_offset: fragment.insertion_offset,
|
||||||
|
fragment_id: fragment.id.clone(),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
insertions.sort_unstable_by_key(|i| (i.timestamp, i.split_offset));
|
||||||
Self {
|
Self {
|
||||||
remote_id,
|
remote_id,
|
||||||
replica_id,
|
replica_id,
|
||||||
|
|
||||||
|
history: History::new("".into()),
|
||||||
|
deferred_ops: OperationQueue::new(),
|
||||||
|
deferred_replicas: Default::default(),
|
||||||
|
local_clock: clock::Local {
|
||||||
|
replica_id,
|
||||||
|
value: version.get(replica_id) + 1,
|
||||||
|
},
|
||||||
|
lamport_clock: clock::Lamport {
|
||||||
|
replica_id,
|
||||||
|
value: lamport_timestamp,
|
||||||
|
},
|
||||||
|
subscriptions: Default::default(),
|
||||||
snapshot: BufferSnapshot {
|
snapshot: BufferSnapshot {
|
||||||
replica_id,
|
replica_id,
|
||||||
visible_text,
|
visible_text,
|
||||||
deleted_text,
|
deleted_text,
|
||||||
undo_map,
|
undo_map: UndoMap(undo_map.collect()),
|
||||||
fragments,
|
fragments,
|
||||||
insertions: (),
|
insertions: SumTree::from_iter(insertions, &()),
|
||||||
version: (),
|
version,
|
||||||
},
|
},
|
||||||
history: History::new("".into()),
|
|
||||||
deferred_ops: OperationQueue::new(),
|
|
||||||
deferred_replicas: Default::default(),
|
|
||||||
last_edit: todo!(),
|
|
||||||
local_clock: todo!(),
|
|
||||||
lamport_clock: todo!(),
|
|
||||||
subscriptions: Default::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +605,6 @@ impl Buffer {
|
|||||||
|
|
||||||
self.history.push(edit.clone());
|
self.history.push(edit.clone());
|
||||||
self.history.push_undo(edit.timestamp.local());
|
self.history.push_undo(edit.timestamp.local());
|
||||||
self.last_edit = edit.timestamp.local();
|
|
||||||
self.snapshot.version.observe(edit.timestamp.local());
|
self.snapshot.version.observe(edit.timestamp.local());
|
||||||
self.end_transaction();
|
self.end_transaction();
|
||||||
edit
|
edit
|
||||||
@@ -1338,16 +1351,7 @@ impl BufferSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fragments(&self) -> impl Iterator<Item = &Fragment> {
|
pub fn fragments(&self) -> impl Iterator<Item = &Fragment> {
|
||||||
let mut cursor = self.fragments.cursor::<()>();
|
self.fragments.iter()
|
||||||
let mut started = false;
|
|
||||||
std::iter::from_fn(move || {
|
|
||||||
if started {
|
|
||||||
cursor.next(&None);
|
|
||||||
} else {
|
|
||||||
started = true;
|
|
||||||
}
|
|
||||||
cursor.item()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_summary(&self) -> TextSummary {
|
pub fn text_summary(&self) -> TextSummary {
|
||||||
|
|||||||
Reference in New Issue
Block a user