diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 32cbc260ec126d29e878d526d0db81aeec9b2f98..f56f6035f629b0f3a9ac9fd5d942e5ff46d8060b 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -357,20 +357,6 @@ impl Buffer { ) } - pub fn from_file>( - replica_id: ReplicaId, - base_text: T, - diff_base: Option, - file: Arc, - cx: &mut ModelContext, - ) -> Self { - Self::build( - TextBuffer::new(replica_id, cx.model_id() as u64, base_text.into()), - diff_base.map(|h| h.into().into_boxed_str().into()), - Some(file), - ) - } - pub fn from_proto( replica_id: ReplicaId, message: proto::BufferState, @@ -460,7 +446,11 @@ impl Buffer { self } - fn build(buffer: TextBuffer, diff_base: Option, file: Option>) -> Self { + pub fn build( + buffer: TextBuffer, + diff_base: Option, + file: Option>, + ) -> Self { let saved_mtime = if let Some(file) = file.as_ref() { file.mtime() } else { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 22661ac92569b0a7349166368457173d1ec5fff3..2b731099ed7e114886e99d76f11b4c1e3f97b8c1 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -109,6 +109,7 @@ pub struct Project { collaborators: HashMap, client_subscriptions: Vec, _subscriptions: Vec, + next_buffer_id: u64, opened_buffer: (watch::Sender<()>, watch::Receiver<()>), shared_buffers: HashMap>, #[allow(clippy::type_complexity)] @@ -441,6 +442,7 @@ impl Project { worktrees: Default::default(), buffer_ordered_messages_tx: tx, collaborators: Default::default(), + next_buffer_id: 0, opened_buffers: Default::default(), shared_buffers: Default::default(), incomplete_remote_buffers: Default::default(), @@ -509,6 +511,7 @@ impl Project { worktrees: Vec::new(), buffer_ordered_messages_tx: tx, loading_buffers_by_path: Default::default(), + next_buffer_id: 0, opened_buffer: watch::channel(), shared_buffers: Default::default(), incomplete_remote_buffers: Default::default(), @@ -1401,9 +1404,10 @@ impl Project { worktree: &ModelHandle, cx: &mut ModelContext, ) -> Task>> { + let buffer_id = post_inc(&mut self.next_buffer_id); let load_buffer = worktree.update(cx, |worktree, cx| { let worktree = worktree.as_local_mut().unwrap(); - worktree.load_buffer(path, cx) + worktree.load_buffer(buffer_id, path, cx) }); cx.spawn(|this, mut cx| async move { let buffer = load_buffer.await?; diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 14fb4f26287e65863945008a64ded26c5ed4d2b6..1281ddeff3f86607cbe5a25990a3171aaab0913e 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -506,6 +506,7 @@ impl LocalWorktree { pub(crate) fn load_buffer( &mut self, + id: u64, path: &Path, cx: &mut ModelContext, ) -> Task>> { @@ -514,8 +515,12 @@ impl LocalWorktree { let (file, contents, diff_base) = this .update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx)) .await?; + let text_buffer = cx + .background() + .spawn(async move { text::Buffer::new(0, id, contents) }) + .await; Ok(cx.add_model(|cx| { - let mut buffer = Buffer::from_file(0, contents, diff_base, Arc::new(file), cx); + let mut buffer = Buffer::build(text_buffer, diff_base, Some(Arc::new(file))); buffer.git_diff_recalc(cx); buffer }))