Ensure prior, deferred selections don't override newer selections
This commit is contained in:
parent
eb65a5d29a
commit
e56609cf0c
3 changed files with 48 additions and 58 deletions
|
@ -65,7 +65,7 @@ pub struct Buffer {
|
||||||
syntax_tree: Mutex<Option<SyntaxTree>>,
|
syntax_tree: Mutex<Option<SyntaxTree>>,
|
||||||
parsing_in_background: bool,
|
parsing_in_background: bool,
|
||||||
parse_count: usize,
|
parse_count: usize,
|
||||||
remote_selections: TreeMap<ReplicaId, Arc<[Selection<Anchor>]>>,
|
remote_selections: TreeMap<ReplicaId, SelectionSet>,
|
||||||
selections_update_count: usize,
|
selections_update_count: usize,
|
||||||
diagnostic_sets: Vec<DiagnosticSet>,
|
diagnostic_sets: Vec<DiagnosticSet>,
|
||||||
diagnostics_update_count: usize,
|
diagnostics_update_count: usize,
|
||||||
|
@ -80,13 +80,19 @@ pub struct BufferSnapshot {
|
||||||
tree: Option<Tree>,
|
tree: Option<Tree>,
|
||||||
diagnostic_sets: Vec<DiagnosticSet>,
|
diagnostic_sets: Vec<DiagnosticSet>,
|
||||||
diagnostics_update_count: usize,
|
diagnostics_update_count: usize,
|
||||||
remote_selections: TreeMap<ReplicaId, Arc<[Selection<Anchor>]>>,
|
remote_selections: TreeMap<ReplicaId, SelectionSet>,
|
||||||
selections_update_count: usize,
|
selections_update_count: usize,
|
||||||
is_parsing: bool,
|
is_parsing: bool,
|
||||||
language: Option<Arc<Language>>,
|
language: Option<Arc<Language>>,
|
||||||
parse_count: usize,
|
parse_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
struct SelectionSet {
|
||||||
|
selections: Arc<[Selection<Anchor>]>,
|
||||||
|
lamport_timestamp: clock::Lamport,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct GroupId {
|
pub struct GroupId {
|
||||||
source: Arc<str>,
|
source: Arc<str>,
|
||||||
|
@ -132,10 +138,6 @@ pub enum Operation {
|
||||||
selections: Arc<[Selection<Anchor>]>,
|
selections: Arc<[Selection<Anchor>]>,
|
||||||
lamport_timestamp: clock::Lamport,
|
lamport_timestamp: clock::Lamport,
|
||||||
},
|
},
|
||||||
RemoveSelections {
|
|
||||||
replica_id: ReplicaId,
|
|
||||||
lamport_timestamp: clock::Lamport,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
@ -311,7 +313,13 @@ impl Buffer {
|
||||||
for selection_set in message.selections {
|
for selection_set in message.selections {
|
||||||
this.remote_selections.insert(
|
this.remote_selections.insert(
|
||||||
selection_set.replica_id as ReplicaId,
|
selection_set.replica_id as ReplicaId,
|
||||||
proto::deserialize_selections(selection_set.selections),
|
SelectionSet {
|
||||||
|
selections: proto::deserialize_selections(selection_set.selections),
|
||||||
|
lamport_timestamp: clock::Lamport {
|
||||||
|
replica_id: selection_set.replica_id as ReplicaId,
|
||||||
|
value: selection_set.lamport_timestamp,
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let snapshot = this.snapshot();
|
let snapshot = this.snapshot();
|
||||||
|
@ -357,9 +365,10 @@ impl Buffer {
|
||||||
selections: self
|
selections: self
|
||||||
.remote_selections
|
.remote_selections
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(replica_id, selections)| proto::SelectionSet {
|
.map(|(replica_id, set)| proto::SelectionSet {
|
||||||
replica_id: *replica_id as u32,
|
replica_id: *replica_id as u32,
|
||||||
selections: proto::serialize_selections(selections),
|
selections: proto::serialize_selections(&set.selections),
|
||||||
|
lamport_timestamp: set.lamport_timestamp.value,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
diagnostic_sets: self
|
diagnostic_sets: self
|
||||||
|
@ -1134,8 +1143,13 @@ 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
|
self.remote_selections.insert(
|
||||||
.insert(self.text.replica_id(), selections.clone());
|
self.text.replica_id(),
|
||||||
|
SelectionSet {
|
||||||
|
selections: selections.clone(),
|
||||||
|
lamport_timestamp,
|
||||||
|
},
|
||||||
|
);
|
||||||
self.send_operation(
|
self.send_operation(
|
||||||
Operation::UpdateSelections {
|
Operation::UpdateSelections {
|
||||||
replica_id: self.text.replica_id(),
|
replica_id: self.text.replica_id(),
|
||||||
|
@ -1147,14 +1161,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_active_selections(&mut self, cx: &mut ModelContext<Self>) {
|
pub fn remove_active_selections(&mut self, cx: &mut ModelContext<Self>) {
|
||||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
self.set_active_selections(Arc::from([]), cx);
|
||||||
self.send_operation(
|
|
||||||
Operation::RemoveSelections {
|
|
||||||
replica_id: self.text.replica_id(),
|
|
||||||
lamport_timestamp,
|
|
||||||
},
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_language_server(&mut self) {
|
fn update_language_server(&mut self) {
|
||||||
|
@ -1378,7 +1385,6 @@ impl Buffer {
|
||||||
Operation::UpdateSelections { selections, .. } => selections
|
Operation::UpdateSelections { selections, .. } => selections
|
||||||
.iter()
|
.iter()
|
||||||
.all(|s| self.can_resolve(&s.start) && self.can_resolve(&s.end)),
|
.all(|s| self.can_resolve(&s.start) && self.can_resolve(&s.end)),
|
||||||
Operation::RemoveSelections { .. } => true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1407,15 +1413,19 @@ impl Buffer {
|
||||||
selections,
|
selections,
|
||||||
lamport_timestamp,
|
lamport_timestamp,
|
||||||
} => {
|
} => {
|
||||||
self.remote_selections.insert(replica_id, selections);
|
if let Some(set) = self.remote_selections.get(&replica_id) {
|
||||||
self.text.lamport_clock.observe(lamport_timestamp);
|
if set.lamport_timestamp > lamport_timestamp {
|
||||||
self.selections_update_count += 1;
|
return;
|
||||||
}
|
}
|
||||||
Operation::RemoveSelections {
|
}
|
||||||
replica_id,
|
|
||||||
lamport_timestamp,
|
self.remote_selections.insert(
|
||||||
} => {
|
replica_id,
|
||||||
self.remote_selections.remove(&replica_id);
|
SelectionSet {
|
||||||
|
selections,
|
||||||
|
lamport_timestamp,
|
||||||
|
},
|
||||||
|
);
|
||||||
self.text.lamport_clock.observe(lamport_timestamp);
|
self.text.lamport_clock.observe(lamport_timestamp);
|
||||||
self.selections_update_count += 1;
|
self.selections_update_count += 1;
|
||||||
}
|
}
|
||||||
|
@ -1812,9 +1822,11 @@ impl BufferSnapshot {
|
||||||
{
|
{
|
||||||
self.remote_selections
|
self.remote_selections
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(replica_id, _)| **replica_id != self.text.replica_id())
|
.filter(|(replica_id, set)| {
|
||||||
.map(move |(replica_id, selections)| {
|
**replica_id != self.text.replica_id() && !set.selections.is_empty()
|
||||||
let start_ix = match selections.binary_search_by(|probe| {
|
})
|
||||||
|
.map(move |(replica_id, set)| {
|
||||||
|
let start_ix = match set.selections.binary_search_by(|probe| {
|
||||||
probe
|
probe
|
||||||
.end
|
.end
|
||||||
.cmp(&range.start, self)
|
.cmp(&range.start, self)
|
||||||
|
@ -1823,7 +1835,7 @@ impl BufferSnapshot {
|
||||||
}) {
|
}) {
|
||||||
Ok(ix) | Err(ix) => ix,
|
Ok(ix) | Err(ix) => ix,
|
||||||
};
|
};
|
||||||
let end_ix = match selections.binary_search_by(|probe| {
|
let end_ix = match set.selections.binary_search_by(|probe| {
|
||||||
probe
|
probe
|
||||||
.start
|
.start
|
||||||
.cmp(&range.end, self)
|
.cmp(&range.end, self)
|
||||||
|
@ -1833,7 +1845,7 @@ impl BufferSnapshot {
|
||||||
Ok(ix) | Err(ix) => ix,
|
Ok(ix) | Err(ix) => ix,
|
||||||
};
|
};
|
||||||
|
|
||||||
(*replica_id, selections[start_ix..end_ix].iter())
|
(*replica_id, set.selections[start_ix..end_ix].iter())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2126,9 +2138,6 @@ impl operation_queue::Operation for Operation {
|
||||||
}
|
}
|
||||||
| Operation::UpdateSelections {
|
| Operation::UpdateSelections {
|
||||||
lamport_timestamp, ..
|
lamport_timestamp, ..
|
||||||
}
|
|
||||||
| Operation::RemoveSelections {
|
|
||||||
lamport_timestamp, ..
|
|
||||||
} => *lamport_timestamp,
|
} => *lamport_timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,13 +50,6 @@ pub fn serialize_operation(operation: &Operation) -> proto::Operation {
|
||||||
lamport_timestamp: lamport_timestamp.value,
|
lamport_timestamp: lamport_timestamp.value,
|
||||||
selections: serialize_selections(selections),
|
selections: serialize_selections(selections),
|
||||||
}),
|
}),
|
||||||
Operation::RemoveSelections {
|
|
||||||
replica_id,
|
|
||||||
lamport_timestamp,
|
|
||||||
} => proto::operation::Variant::RemoveSelections(proto::operation::RemoveSelections {
|
|
||||||
replica_id: *replica_id as u32,
|
|
||||||
lamport_timestamp: lamport_timestamp.value,
|
|
||||||
}),
|
|
||||||
Operation::UpdateDiagnostics {
|
Operation::UpdateDiagnostics {
|
||||||
provider_name,
|
provider_name,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
|
@ -246,13 +239,6 @@ pub fn deserialize_operation(message: proto::Operation) -> Result<Operation> {
|
||||||
selections: Arc::from(selections),
|
selections: Arc::from(selections),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proto::operation::Variant::RemoveSelections(message) => Operation::RemoveSelections {
|
|
||||||
replica_id: message.replica_id as ReplicaId,
|
|
||||||
lamport_timestamp: clock::Lamport {
|
|
||||||
replica_id: message.replica_id as ReplicaId,
|
|
||||||
value: message.lamport_timestamp,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
proto::operation::Variant::UpdateDiagnosticSet(message) => {
|
proto::operation::Variant::UpdateDiagnosticSet(message) => {
|
||||||
let (provider_name, diagnostics) = deserialize_diagnostic_set(
|
let (provider_name, diagnostics) = deserialize_diagnostic_set(
|
||||||
message
|
message
|
||||||
|
|
|
@ -287,6 +287,7 @@ message BufferFragment {
|
||||||
message SelectionSet {
|
message SelectionSet {
|
||||||
uint32 replica_id = 1;
|
uint32 replica_id = 1;
|
||||||
repeated Selection selections = 2;
|
repeated Selection selections = 2;
|
||||||
|
uint32 lamport_timestamp = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Selection {
|
message Selection {
|
||||||
|
@ -344,8 +345,7 @@ message Operation {
|
||||||
Edit edit = 1;
|
Edit edit = 1;
|
||||||
Undo undo = 2;
|
Undo undo = 2;
|
||||||
UpdateSelections update_selections = 3;
|
UpdateSelections update_selections = 3;
|
||||||
RemoveSelections remove_selections = 4;
|
UpdateDiagnosticSet update_diagnostic_set = 4;
|
||||||
UpdateDiagnosticSet update_diagnostic_set = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message Edit {
|
message Edit {
|
||||||
|
@ -371,11 +371,6 @@ message Operation {
|
||||||
uint32 lamport_timestamp = 3;
|
uint32 lamport_timestamp = 3;
|
||||||
repeated Selection selections = 4;
|
repeated Selection selections = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RemoveSelections {
|
|
||||||
uint32 replica_id = 1;
|
|
||||||
uint32 lamport_timestamp = 3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message UndoMapEntry {
|
message UndoMapEntry {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue