Add the ability to propose changes to a set of buffers (#18170)

This PR introduces functionality for creating *branches* of buffers that
can be used to preview and edit change sets that haven't yet been
applied to the buffers themselves.

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-09-20 15:28:50 -07:00 committed by GitHub
parent e309fbda2a
commit 743feb98bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 622 additions and 186 deletions

View file

@ -13,6 +13,7 @@ mod undo_map;
pub use anchor::*;
use anyhow::{anyhow, Context as _, Result};
pub use clock::ReplicaId;
use clock::LOCAL_BRANCH_REPLICA_ID;
use collections::{HashMap, HashSet};
use locator::Locator;
use operation_queue::OperationQueue;
@ -715,6 +716,19 @@ impl Buffer {
self.snapshot.clone()
}
pub fn branch(&self) -> Self {
Self {
snapshot: self.snapshot.clone(),
history: History::new(self.base_text().clone()),
deferred_ops: OperationQueue::new(),
deferred_replicas: HashSet::default(),
lamport_clock: clock::Lamport::new(LOCAL_BRANCH_REPLICA_ID),
subscriptions: Default::default(),
edit_id_resolvers: Default::default(),
wait_for_version_txs: Default::default(),
}
}
pub fn replica_id(&self) -> ReplicaId {
self.lamport_clock.replica_id
}