Fix Global::gt
and rename it to changed_since
A false negative return value of `gt` was preventing guests' multibuffers from syncing correctly. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
4b22e49ce1
commit
e5faaeb2f2
4 changed files with 41 additions and 26 deletions
|
@ -178,7 +178,7 @@ impl Global {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ge(&self, other: &Self) -> bool {
|
pub fn observed_all(&self, other: &Self) -> bool {
|
||||||
let mut lhs = self.0.iter();
|
let mut lhs = self.0.iter();
|
||||||
let mut rhs = other.0.iter();
|
let mut rhs = other.0.iter();
|
||||||
loop {
|
loop {
|
||||||
|
@ -196,22 +196,16 @@ impl Global {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gt(&self, other: &Self) -> bool {
|
pub fn changed_since(&self, other: &Self) -> bool {
|
||||||
let mut lhs = self.0.iter();
|
if self.0.len() > other.0.len() {
|
||||||
let mut rhs = other.0.iter();
|
return true;
|
||||||
loop {
|
}
|
||||||
if let Some(left) = lhs.next() {
|
for (left, right) in self.0.iter().zip(other.0.iter()) {
|
||||||
if let Some(right) = rhs.next() {
|
if left > right {
|
||||||
if left <= right {
|
return true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return rhs.next().is_none();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter<'a>(&'a self) -> impl 'a + Iterator<Item = Local> {
|
pub fn iter<'a>(&'a self) -> impl 'a + Iterator<Item = Local> {
|
||||||
|
|
|
@ -804,7 +804,7 @@ impl MultiBuffer {
|
||||||
let selections_update_count = buffer.selections_update_count();
|
let selections_update_count = buffer.selections_update_count();
|
||||||
let diagnostics_update_count = buffer.diagnostics_update_count();
|
let diagnostics_update_count = buffer.diagnostics_update_count();
|
||||||
|
|
||||||
let buffer_edited = version.gt(&buffer_state.last_version);
|
let buffer_edited = version.changed_since(&buffer_state.last_version);
|
||||||
let buffer_reparsed = parse_count > buffer_state.last_parse_count;
|
let buffer_reparsed = parse_count > buffer_state.last_parse_count;
|
||||||
let buffer_selections_updated =
|
let buffer_selections_updated =
|
||||||
selections_update_count > buffer_state.last_selections_update_count;
|
selections_update_count > buffer_state.last_selections_update_count;
|
||||||
|
@ -2116,6 +2116,26 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_remote_multibuffer(cx: &mut MutableAppContext) {
|
||||||
|
let host_buffer = cx.add_model(|cx| Buffer::new(0, "a", cx));
|
||||||
|
let guest_buffer = cx.add_model(|cx| {
|
||||||
|
let message = host_buffer.read(cx).to_proto();
|
||||||
|
Buffer::from_proto(1, message, None, cx).unwrap()
|
||||||
|
});
|
||||||
|
let multibuffer = cx.add_model(|cx| MultiBuffer::singleton(guest_buffer.clone(), cx));
|
||||||
|
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||||
|
assert_eq!(snapshot.text(), "a");
|
||||||
|
|
||||||
|
guest_buffer.update(cx, |buffer, cx| buffer.edit([1..1], "b", cx));
|
||||||
|
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||||
|
assert_eq!(snapshot.text(), "ab");
|
||||||
|
|
||||||
|
guest_buffer.update(cx, |buffer, cx| buffer.edit([2..2], "c", cx));
|
||||||
|
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||||
|
assert_eq!(snapshot.text(), "abc");
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn test_excerpt_buffer(cx: &mut MutableAppContext) {
|
fn test_excerpt_buffer(cx: &mut MutableAppContext) {
|
||||||
let buffer_1 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'a'), cx));
|
let buffer_1 = cx.add_model(|cx| Buffer::new(0, sample_text(6, 6, 'a'), cx));
|
||||||
|
|
|
@ -725,7 +725,8 @@ impl Buffer {
|
||||||
let grammar_changed = this
|
let grammar_changed = this
|
||||||
.grammar()
|
.grammar()
|
||||||
.map_or(true, |curr_grammar| !Arc::ptr_eq(&grammar, curr_grammar));
|
.map_or(true, |curr_grammar| !Arc::ptr_eq(&grammar, curr_grammar));
|
||||||
let parse_again = this.version.gt(&parsed_version) || grammar_changed;
|
let parse_again =
|
||||||
|
this.version.changed_since(&parsed_version) || grammar_changed;
|
||||||
this.parsing_in_background = false;
|
this.parsing_in_background = false;
|
||||||
this.did_finish_parsing(new_tree, parsed_version, cx);
|
this.did_finish_parsing(new_tree, parsed_version, cx);
|
||||||
|
|
||||||
|
@ -1095,12 +1096,12 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_dirty(&self) -> bool {
|
pub fn is_dirty(&self) -> bool {
|
||||||
!self.saved_version.ge(&self.version)
|
!self.saved_version.observed_all(&self.version)
|
||||||
|| self.file.as_ref().map_or(false, |file| file.is_deleted())
|
|| self.file.as_ref().map_or(false, |file| file.is_deleted())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_conflict(&self) -> bool {
|
pub fn has_conflict(&self) -> bool {
|
||||||
!self.saved_version.ge(&self.version)
|
!self.saved_version.observed_all(&self.version)
|
||||||
&& self
|
&& self
|
||||||
.file
|
.file
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
@ -1125,8 +1125,8 @@ impl Buffer {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
match op {
|
match op {
|
||||||
Operation::Edit(edit) => self.version.ge(&edit.version),
|
Operation::Edit(edit) => self.version.observed_all(&edit.version),
|
||||||
Operation::Undo { undo, .. } => self.version.ge(&undo.version),
|
Operation::Undo { undo, .. } => self.version.observed_all(&undo.version),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1648,10 +1648,10 @@ impl BufferSnapshot {
|
||||||
let fragments_cursor = if *since == self.version {
|
let fragments_cursor = if *since == self.version {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(
|
Some(self.fragments.filter(
|
||||||
self.fragments
|
move |summary| !since.observed_all(&summary.max_version),
|
||||||
.filter(move |summary| !since.ge(&summary.max_version), &None),
|
&None,
|
||||||
)
|
))
|
||||||
};
|
};
|
||||||
let mut cursor = self
|
let mut cursor = self
|
||||||
.fragments
|
.fragments
|
||||||
|
@ -2025,7 +2025,7 @@ impl<'a> sum_tree::Dimension<'a, FragmentSummary> for VersionedFullOffset {
|
||||||
fn add_summary(&mut self, summary: &'a FragmentSummary, cx: &Option<clock::Global>) {
|
fn add_summary(&mut self, summary: &'a FragmentSummary, cx: &Option<clock::Global>) {
|
||||||
if let Self::Offset(offset) = self {
|
if let Self::Offset(offset) = self {
|
||||||
let version = cx.as_ref().unwrap();
|
let version = cx.as_ref().unwrap();
|
||||||
if version.ge(&summary.max_insertion_version) {
|
if version.observed_all(&summary.max_insertion_version) {
|
||||||
*offset += summary.text.visible + summary.text.deleted;
|
*offset += summary.text.visible + summary.text.deleted;
|
||||||
} else if version.observed_any(&summary.min_insertion_version) {
|
} else if version.observed_any(&summary.min_insertion_version) {
|
||||||
*self = Self::Invalid;
|
*self = Self::Invalid;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue