Skip COMMIT_EDITMSG contents when opening the file (#24146)
This commit is contained in:
parent
225f0c4d12
commit
ea66a54cf8
9 changed files with 110 additions and 48 deletions
|
@ -329,6 +329,7 @@ impl RemoteBufferStore {
|
|||
&self,
|
||||
path: Arc<Path>,
|
||||
worktree: Entity<Worktree>,
|
||||
skip_file_contents: bool,
|
||||
cx: &mut Context<BufferStore>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
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<Path>,
|
||||
worktree: Entity<Worktree>,
|
||||
skip_file_contents: bool,
|
||||
cx: &mut Context<BufferStore>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
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<Self>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
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::<Vec<_>>()
|
||||
})?;
|
||||
for buffer_task in buffers {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<ProjectPath>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<Entity<Buffer>>> {
|
||||
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<proto::OpenBufferResponse> {
|
||||
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:?}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue