diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index ac622aaa42..d6176a8491 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -130,14 +130,34 @@ fn commit_message_buffer( ) .await .with_context(|| format!("creating commit message file {commit_message_file:?}"))?; - let buffer = project + let (worktree, relative_path) = project .update(&mut cx, |project, cx| { - project.open_local_buffer(&commit_message_file, cx) + project.worktree_store().update(cx, |worktree_store, cx| { + worktree_store.find_or_create_worktree(&commit_message_file, false, cx) + }) })? .await .with_context(|| { - format!("opening commit message buffer at {commit_message_file:?}",) + format!("deriving worktree for commit message file {commit_message_file:?}") })?; + + let buffer = project + .update(&mut cx, |project, cx| { + project.buffer_store().update(cx, |buffer_store, cx| { + buffer_store.open_buffer( + ProjectPath { + worktree_id: worktree.read(cx).id(), + path: Arc::from(relative_path), + }, + true, + cx, + ) + }) + }) + .with_context(|| { + format!("opening buffer for commit message file {commit_message_file:?}") + })? + .await?; Ok(buffer) }) } @@ -211,7 +231,6 @@ impl GitPanel { pub fn new( workspace: &mut Workspace, window: &mut Window, - commit_message_buffer: Option>, cx: &mut Context, ) -> Entity { let fs = workspace.app_state().fs.clone(); @@ -229,12 +248,7 @@ impl GitPanel { }) .detach(); - let commit_editor = - cx.new(|cx| commit_message_editor(commit_message_buffer, window, cx)); - commit_editor.update(cx, |editor, cx| { - editor.clear(window, cx); - }); - + let commit_editor = cx.new(|cx| commit_message_editor(None, window, cx)); let scroll_handle = UniformListScrollHandle::new(); cx.subscribe_in( diff --git a/crates/project/src/buffer_store.rs b/crates/project/src/buffer_store.rs index 69ba50347b..01c3878d6c 100644 --- a/crates/project/src/buffer_store.rs +++ b/crates/project/src/buffer_store.rs @@ -329,6 +329,7 @@ impl RemoteBufferStore { &self, path: Arc, worktree: Entity, + skip_file_contents: bool, cx: &mut Context, ) -> Task>> { let worktree_id = worktree.read(cx).id().to_proto(); @@ -341,6 +342,7 @@ impl RemoteBufferStore { project_id, worktree_id, path: path_string, + skip_file_contents, }) .await?; let buffer_id = BufferId::new(response.buffer_id)?; @@ -786,10 +788,11 @@ impl LocalBufferStore { &self, path: Arc, worktree: Entity, + skip_file_contents: bool, cx: &mut Context, ) -> Task>> { let load_buffer = worktree.update(cx, |worktree, cx| { - let load_file = worktree.load_file(path.as_ref(), cx); + let load_file = worktree.load_file(path.as_ref(), skip_file_contents, cx); let reservation = cx.reserve_entity(); let buffer_id = BufferId::from(reservation.entity_id().as_non_zero_u64()); cx.spawn(move |_, mut cx| async move { @@ -973,6 +976,7 @@ impl BufferStore { pub fn open_buffer( &mut self, project_path: ProjectPath, + skip_file_contents: bool, cx: &mut Context, ) -> Task>> { if let Some(buffer) = self.get_by_path(&project_path, cx) { @@ -991,8 +995,12 @@ impl BufferStore { return Task::ready(Err(anyhow!("no such worktree"))); }; let load_buffer = match &self.state { - BufferStoreState::Local(this) => this.open_buffer(path, worktree, cx), - BufferStoreState::Remote(this) => this.open_buffer(path, worktree, cx), + BufferStoreState::Local(this) => { + this.open_buffer(path, worktree, skip_file_contents, cx) + } + BufferStoreState::Remote(this) => { + this.open_buffer(path, worktree, skip_file_contents, cx) + } }; entry @@ -1485,7 +1493,7 @@ impl BufferStore { let buffers = this.update(&mut cx, |this, cx| { project_paths .into_iter() - .map(|project_path| this.open_buffer(project_path, cx)) + .map(|project_path| this.open_buffer(project_path, false, cx)) .collect::>() })?; for buffer_task in buffers { diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 8b1f1c8efc..f5097e6f8c 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -5616,7 +5616,7 @@ impl LspStore { lsp_store .update(&mut cx, |lsp_store, cx| { lsp_store.buffer_store().update(cx, |buffer_store, cx| { - buffer_store.open_buffer(project_path, cx) + buffer_store.open_buffer(project_path, false, cx) }) })? .await diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index bb88982959..c3e19bfeb0 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1933,7 +1933,21 @@ impl Project { } self.buffer_store.update(cx, |buffer_store, cx| { - buffer_store.open_buffer(path.into(), cx) + buffer_store.open_buffer(path.into(), false, cx) + }) + } + + pub fn open_buffer_without_contents( + &mut self, + path: impl Into, + cx: &mut Context, + ) -> Task>> { + if self.is_disconnected(cx) { + return Task::ready(Err(anyhow!(ErrorCode::Disconnected))); + } + + self.buffer_store.update(cx, |buffer_store, cx| { + buffer_store.open_buffer(path.into(), true, cx) }) } @@ -3937,14 +3951,25 @@ impl Project { ) -> Result { let peer_id = envelope.original_sender_id()?; let worktree_id = WorktreeId::from_proto(envelope.payload.worktree_id); + let skip_file_contents = envelope.payload.skip_file_contents; let open_buffer = this.update(&mut cx, |this, cx| { - this.open_buffer( - ProjectPath { - worktree_id, - path: PathBuf::from(envelope.payload.path).into(), - }, - cx, - ) + if skip_file_contents { + this.open_buffer_without_contents( + ProjectPath { + worktree_id, + path: PathBuf::from(envelope.payload.path).into(), + }, + cx, + ) + } else { + this.open_buffer( + ProjectPath { + worktree_id, + path: PathBuf::from(envelope.payload.path).into(), + }, + cx, + ) + } })?; let buffer = open_buffer.await?; @@ -4073,12 +4098,10 @@ impl Project { .with_context(|| format!("creating commit message file {commit_message_file:?}"))?; let (worktree, relative_path) = this - .update(&mut cx, |headless_project, cx| { - headless_project - .worktree_store - .update(cx, |worktree_store, cx| { - worktree_store.find_or_create_worktree(&commit_message_file, false, cx) - }) + .update(&mut cx, |project, cx| { + project.worktree_store.update(cx, |worktree_store, cx| { + worktree_store.find_or_create_worktree(&commit_message_file, false, cx) + }) })? .await .with_context(|| { @@ -4086,18 +4109,17 @@ impl Project { })?; let buffer = this - .update(&mut cx, |headless_project, cx| { - headless_project - .buffer_store - .update(cx, |buffer_store, cx| { - buffer_store.open_buffer( - ProjectPath { - worktree_id: worktree.read(cx).id(), - path: Arc::from(relative_path), - }, - cx, - ) - }) + .update(&mut cx, |project, cx| { + project.buffer_store.update(cx, |buffer_store, cx| { + buffer_store.open_buffer( + ProjectPath { + worktree_id: worktree.read(cx).id(), + path: Arc::from(relative_path), + }, + true, + cx, + ) + }) }) .with_context(|| { format!("opening buffer for commit message file {commit_message_file:?}") diff --git a/crates/proto/proto/zed.proto b/crates/proto/proto/zed.proto index c719038921..1b0cd2e2e8 100644 --- a/crates/proto/proto/zed.proto +++ b/crates/proto/proto/zed.proto @@ -795,6 +795,7 @@ message OpenBufferByPath { uint64 project_id = 1; uint64 worktree_id = 2; string path = 3; + bool skip_file_contents = 4; } message OpenBufferById { diff --git a/crates/remote_server/src/headless_project.rs b/crates/remote_server/src/headless_project.rs index fbea10fdea..8d387583fd 100644 --- a/crates/remote_server/src/headless_project.rs +++ b/crates/remote_server/src/headless_project.rs @@ -421,6 +421,7 @@ impl HeadlessProject { worktree_id, path: PathBuf::from(message.payload.path).into(), }, + message.payload.skip_file_contents, cx, ) }); @@ -487,6 +488,7 @@ impl HeadlessProject { worktree_id: worktree.read(cx).id(), path: path.into(), }, + false, cx, ) }); @@ -749,6 +751,7 @@ impl HeadlessProject { worktree_id: worktree.read(cx).id(), path: Arc::from(relative_path), }, + true, cx, ) }) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index f41caf2100..42f4c07512 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -862,9 +862,14 @@ impl Worktree { } } - pub fn load_file(&self, path: &Path, cx: &Context) -> Task> { + pub fn load_file( + &self, + path: &Path, + skip_file_contents: bool, + cx: &Context, + ) -> Task> { match self { - Worktree::Local(this) => this.load_file(path, cx), + Worktree::Local(this) => this.load_file(path, skip_file_contents, cx), Worktree::Remote(_) => { Task::ready(Err(anyhow!("remote worktrees can't yet load files"))) } @@ -1582,7 +1587,12 @@ impl LocalWorktree { }) } - fn load_file(&self, path: &Path, cx: &Context) -> Task> { + fn load_file( + &self, + path: &Path, + skip_file_contents: bool, + cx: &Context, + ) -> Task> { let path = Arc::from(path); let abs_path = self.absolutize(&path); let fs = self.fs.clone(); @@ -1591,7 +1601,11 @@ impl LocalWorktree { cx.spawn(|this, _cx| async move { let abs_path = abs_path?; - let text = fs.load(&abs_path).await?; + let text = if skip_file_contents { + String::new() + } else { + fs.load(&abs_path).await? + }; let worktree = this .upgrade() diff --git a/crates/worktree/src/worktree_tests.rs b/crates/worktree/src/worktree_tests.rs index 533ae7eb87..b5f8af8ea9 100644 --- a/crates/worktree/src/worktree_tests.rs +++ b/crates/worktree/src/worktree_tests.rs @@ -467,7 +467,7 @@ async fn test_open_gitignored_files(cx: &mut TestAppContext) { let prev_read_dir_count = fs.read_dir_call_count(); let loaded = tree .update(cx, |tree, cx| { - tree.load_file("one/node_modules/b/b1.js".as_ref(), cx) + tree.load_file("one/node_modules/b/b1.js".as_ref(), false, cx) }) .await .unwrap(); @@ -507,7 +507,7 @@ async fn test_open_gitignored_files(cx: &mut TestAppContext) { let prev_read_dir_count = fs.read_dir_call_count(); let loaded = tree .update(cx, |tree, cx| { - tree.load_file("one/node_modules/a/a2.js".as_ref(), cx) + tree.load_file("one/node_modules/a/a2.js".as_ref(), false, cx) }) .await .unwrap(); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 3daa543855..712b4a4b97 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -404,7 +404,7 @@ fn initialize_panels( workspace.add_panel(chat_panel, window, cx); workspace.add_panel(notification_panel, window, cx); cx.when_flag_enabled::(window, |workspace, window, cx| { - let git_panel = git_ui::git_panel::GitPanel::new(workspace, window, None, cx); + let git_panel = git_ui::git_panel::GitPanel::new(workspace, window, cx); workspace.add_panel(git_panel, window, cx); }); })?;