Rebuild buffer store to be aware of remote/local distinction (#18303)

Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Conrad Irwin 2024-09-24 15:52:30 -06:00 committed by GitHub
parent da1ef13442
commit c4e0f5e0ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1127 additions and 826 deletions

View file

@ -3,6 +3,7 @@ use call::ActiveCall;
use fs::{FakeFs, Fs as _};
use gpui::{Context as _, TestAppContext};
use language::language_settings::all_language_settings;
use project::ProjectPath;
use remote::SshSession;
use remote_server::HeadlessProject;
use serde_json::json;
@ -108,14 +109,36 @@ async fn test_sharing_an_ssh_remote_project(
});
project_b
.update(cx_b, |project, cx| project.save_buffer(buffer_b, cx))
.update(cx_b, |project, cx| {
project.save_buffer_as(
buffer_b.clone(),
ProjectPath {
worktree_id: worktree_id.to_owned(),
path: Arc::from(Path::new("src/renamed.rs")),
},
cx,
)
})
.await
.unwrap();
assert_eq!(
remote_fs
.load("/code/project1/src/lib.rs".as_ref())
.load("/code/project1/src/renamed.rs".as_ref())
.await
.unwrap(),
"fn one() -> usize { 100 }"
);
cx_b.run_until_parked();
cx_b.update(|cx| {
assert_eq!(
buffer_b
.read(cx)
.file()
.unwrap()
.path()
.to_string_lossy()
.to_string(),
"src/renamed.rs".to_string()
);
});
}

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,9 @@
mod signature_help;
use crate::{
buffer_store::BufferStore, lsp_store::LspStore, CodeAction, CoreCompletion, DocumentHighlight,
Hover, HoverBlock, HoverBlockKind, InlayHint, InlayHintLabel, InlayHintLabelPart,
InlayHintLabelPartTooltip, InlayHintTooltip, Location, LocationLink, MarkupContent,
ProjectTransaction, ResolveState,
lsp_store::LspStore, CodeAction, CoreCompletion, DocumentHighlight, Hover, HoverBlock,
HoverBlockKind, InlayHint, InlayHintLabel, InlayHintLabelPart, InlayHintLabelPartTooltip,
InlayHintTooltip, Location, LocationLink, MarkupContent, ProjectTransaction, ResolveState,
};
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
@ -417,18 +416,18 @@ impl LspCommand for PerformRename {
message: proto::PerformRenameResponse,
lsp_store: Model<LspStore>,
_: Model<Buffer>,
cx: AsyncAppContext,
mut cx: AsyncAppContext,
) -> Result<ProjectTransaction> {
let message = message
.transaction
.ok_or_else(|| anyhow!("missing transaction"))?;
BufferStore::deserialize_project_transaction(
lsp_store.read_with(&cx, |lsp_store, _| lsp_store.buffer_store().downgrade())?,
message,
self.push_to_history,
cx,
)
.await
lsp_store
.update(&mut cx, |lsp_store, cx| {
lsp_store.buffer_store().update(cx, |buffer_store, cx| {
buffer_store.deserialize_project_transaction(message, self.push_to_history, cx)
})
})?
.await
}
fn buffer_id_from_proto(message: &proto::PerformRename) -> Result<BufferId> {

View file

@ -1601,19 +1601,19 @@ impl LspStore {
buffer_id: buffer_handle.read(cx).remote_id().into(),
action: Some(Self::serialize_code_action(&action)),
};
cx.spawn(move |this, cx| async move {
let buffer_store = self.buffer_store();
cx.spawn(move |_, mut cx| async move {
let response = upstream_client
.request(request)
.await?
.transaction
.ok_or_else(|| anyhow!("missing transaction"))?;
BufferStore::deserialize_project_transaction(
this.read_with(&cx, |this, _| this.buffer_store.downgrade())?,
response,
push_to_history,
cx,
)
.await
buffer_store
.update(&mut cx, |buffer_store, cx| {
buffer_store.deserialize_project_transaction(response, push_to_history, cx)
})?
.await
})
} else {
let buffer = buffer_handle.read(cx);
@ -5062,6 +5062,7 @@ impl LspStore {
.spawn(this.languages.language_for_name(language_name.0.as_ref()))
.detach();
// host
let adapter = this.languages.get_or_register_lsp_adapter(
language_name.clone(),
server_name.clone(),
@ -5259,7 +5260,8 @@ impl LspStore {
result
})
} else if let Some((client, project_id)) = self.upstream_client() {
cx.spawn(move |this, mut cx| async move {
let buffer_store = self.buffer_store();
cx.spawn(move |_, mut cx| async move {
let response = client
.request(proto::FormatBuffers {
project_id,
@ -5274,13 +5276,12 @@ impl LspStore {
.await?
.transaction
.ok_or_else(|| anyhow!("missing transaction"))?;
BufferStore::deserialize_project_transaction(
this.read_with(&cx, |this, _| this.buffer_store.downgrade())?,
response,
push_to_history,
cx,
)
.await
buffer_store
.update(&mut cx, |buffer_store, cx| {
buffer_store.deserialize_project_transaction(response, push_to_history, cx)
})?
.await
})
} else {
Task::ready(Ok(ProjectTransaction::default()))

View file

@ -1667,16 +1667,8 @@ impl Project {
}
pub fn create_buffer(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<Model<Buffer>>> {
self.buffer_store.update(cx, |buffer_store, cx| {
buffer_store.create_buffer(
if self.is_via_collab() {
Some((self.client.clone().into(), self.remote_id().unwrap()))
} else {
None
},
cx,
)
})
self.buffer_store
.update(cx, |buffer_store, cx| buffer_store.create_buffer(cx))
}
pub fn create_local_buffer(
@ -1685,7 +1677,7 @@ impl Project {
language: Option<Arc<Language>>,
cx: &mut ModelContext<Self>,
) -> Model<Buffer> {
if self.is_via_collab() {
if self.is_via_collab() || self.is_via_ssh() {
panic!("called create_local_buffer on a remote project")
}
self.buffer_store.update(cx, |buffer_store, cx| {
@ -3770,7 +3762,9 @@ impl Project {
envelope: TypedEnvelope<proto::OpenNewBuffer>,
mut cx: AsyncAppContext,
) -> Result<proto::OpenBufferResponse> {
let buffer = this.update(&mut cx, |this, cx| this.create_local_buffer("", None, cx))?;
let buffer = this
.update(&mut cx, |this, cx| this.create_buffer(cx))?
.await?;
let peer_id = envelope.original_sender_id()?;
Project::respond_to_open_buffer_request(this, buffer, peer_id, &mut cx)

View file

@ -56,6 +56,7 @@ async fn test_basic_remote_editing(cx: &mut TestAppContext, server_cx: &mut Test
})
.await
.unwrap();
buffer.update(cx, |buffer, cx| {
assert_eq!(buffer.text(), "fn one() -> usize { 1 }");
assert_eq!(