Skip to content

Commit fff37ab

Browse files
authored
Follow-up fixes for recent multi buffer optimizations (#26345)
I realized that the optimization broke multi buffer syncing after buffer reparses. Release Notes: - N/A
1 parent 8a7a78f commit fff37ab

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/language/src/buffer.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@ impl Buffer {
15271527
}
15281528

15291529
fn did_finish_parsing(&mut self, syntax_snapshot: SyntaxSnapshot, cx: &mut Context<Self>) {
1530+
self.was_changed();
15301531
self.non_text_state_update_count += 1;
15311532
self.syntax_map.lock().did_parse(syntax_snapshot);
15321533
self.request_autoindent(cx);
@@ -1968,7 +1969,12 @@ impl Buffer {
19681969
/// This allows downstream code to check if the buffer's text has changed without
19691970
/// waiting for an effect cycle, which would be required if using eents.
19701971
pub fn record_changes(&mut self, bit: rc::Weak<Cell<bool>>) {
1971-
self.change_bits.push(bit);
1972+
if let Err(ix) = self
1973+
.change_bits
1974+
.binary_search_by_key(&rc::Weak::as_ptr(&bit), rc::Weak::as_ptr)
1975+
{
1976+
self.change_bits.insert(ix, bit);
1977+
}
19721978
}
19731979

19741980
fn was_changed(&mut self) {
@@ -2273,12 +2279,13 @@ impl Buffer {
22732279
}
22742280

22752281
fn did_edit(&mut self, old_version: &clock::Global, was_dirty: bool, cx: &mut Context<Self>) {
2282+
self.was_changed();
2283+
22762284
if self.edits_since::<usize>(old_version).next().is_none() {
22772285
return;
22782286
}
22792287

22802288
self.reparse(cx);
2281-
22822289
cx.emit(BufferEvent::Edited);
22832290
if was_dirty != self.is_dirty() {
22842291
cx.emit(BufferEvent::DirtyChanged);
@@ -2390,7 +2397,6 @@ impl Buffer {
23902397
}
23912398
self.text.apply_ops(buffer_ops);
23922399
self.deferred_ops.insert(deferred_ops);
2393-
self.was_changed();
23942400
self.flush_deferred_ops(cx);
23952401
self.did_edit(&old_version, was_dirty, cx);
23962402
// Notify independently of whether the buffer was edited as the operations could include a

0 commit comments

Comments
 (0)