Move shared_buffers into BufferStore (#17020)
This also updates the SSH protocol (but not yet collab) to more closely track which buffers are open on the client. Release Notes: - N/A
This commit is contained in:
parent
0853cb573f
commit
9beb4d4380
6 changed files with 335 additions and 233 deletions
|
@ -55,6 +55,7 @@ impl HeadlessProject {
|
|||
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_blame_buffer);
|
||||
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_update_buffer);
|
||||
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_save_buffer);
|
||||
session.add_message_handler(buffer_store.downgrade(), BufferStore::handle_close_buffer);
|
||||
|
||||
session.add_request_handler(
|
||||
worktree_store.downgrade(),
|
||||
|
@ -143,19 +144,11 @@ impl HeadlessProject {
|
|||
|
||||
let buffer = buffer.await?;
|
||||
let buffer_id = buffer.read_with(&cx, |b, _| b.remote_id())?;
|
||||
|
||||
cx.spawn(|mut cx| async move {
|
||||
BufferStore::create_buffer_for_peer(
|
||||
buffer_store,
|
||||
PEER_ID,
|
||||
buffer_id,
|
||||
PROJECT_ID,
|
||||
session,
|
||||
&mut cx,
|
||||
)
|
||||
.await
|
||||
})
|
||||
.detach();
|
||||
buffer_store.update(&mut cx, |buffer_store, cx| {
|
||||
buffer_store
|
||||
.create_buffer_for_peer(&buffer, PEER_ID, PROJECT_ID, session, cx)
|
||||
.detach_and_log_err(cx);
|
||||
})?;
|
||||
|
||||
Ok(proto::OpenBufferResponse {
|
||||
buffer_id: buffer_id.to_proto(),
|
||||
|
@ -190,16 +183,17 @@ impl HeadlessProject {
|
|||
while let Some(buffer) = results.next().await {
|
||||
let buffer_id = buffer.update(&mut cx, |this, _| this.remote_id())?;
|
||||
response.buffer_ids.push(buffer_id.to_proto());
|
||||
|
||||
BufferStore::create_buffer_for_peer(
|
||||
buffer_store.clone(),
|
||||
PEER_ID,
|
||||
buffer_id,
|
||||
PROJECT_ID,
|
||||
client.clone(),
|
||||
&mut cx,
|
||||
)
|
||||
.await?;
|
||||
buffer_store
|
||||
.update(&mut cx, |buffer_store, cx| {
|
||||
buffer_store.create_buffer_for_peer(
|
||||
&buffer,
|
||||
PEER_ID,
|
||||
PROJECT_ID,
|
||||
client.clone(),
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(response)
|
||||
|
|
|
@ -4,7 +4,7 @@ use clock::FakeSystemClock;
|
|||
use fs::{FakeFs, Fs};
|
||||
use gpui::{Context, Model, TestAppContext};
|
||||
use http_client::FakeHttpClient;
|
||||
use language::LanguageRegistry;
|
||||
use language::{Buffer, LanguageRegistry};
|
||||
use node_runtime::FakeNodeRuntime;
|
||||
use project::{
|
||||
search::{SearchQuery, SearchResult},
|
||||
|
@ -121,7 +121,7 @@ async fn test_remote_editing(cx: &mut TestAppContext, server_cx: &mut TestAppCon
|
|||
|
||||
#[gpui::test]
|
||||
async fn test_remote_project_search(cx: &mut TestAppContext, server_cx: &mut TestAppContext) {
|
||||
let (project, _, _) = init_test(cx, server_cx).await;
|
||||
let (project, headless, _) = init_test(cx, server_cx).await;
|
||||
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
|
@ -132,33 +132,55 @@ async fn test_remote_project_search(cx: &mut TestAppContext, server_cx: &mut Tes
|
|||
|
||||
cx.run_until_parked();
|
||||
|
||||
let mut receiver = project.update(cx, |project, cx| {
|
||||
project.search(
|
||||
SearchQuery::text(
|
||||
"project",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
async fn do_search(project: &Model<Project>, mut cx: TestAppContext) -> Model<Buffer> {
|
||||
let mut receiver = project.update(&mut cx, |project, cx| {
|
||||
project.search(
|
||||
SearchQuery::text(
|
||||
"project",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap(),
|
||||
cx,
|
||||
)
|
||||
.unwrap(),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
let first_response = receiver.next().await.unwrap();
|
||||
let SearchResult::Buffer { buffer, .. } = first_response else {
|
||||
panic!("incorrect result");
|
||||
};
|
||||
buffer.update(&mut cx, |buffer, cx| {
|
||||
assert_eq!(
|
||||
buffer.file().unwrap().full_path(cx).to_string_lossy(),
|
||||
"project1/README.md"
|
||||
)
|
||||
});
|
||||
|
||||
assert!(receiver.next().await.is_none());
|
||||
buffer
|
||||
}
|
||||
|
||||
let buffer = do_search(&project, cx.clone()).await;
|
||||
|
||||
// test that the headless server is tracking which buffers we have open correctly.
|
||||
cx.run_until_parked();
|
||||
headless.update(server_cx, |headless, cx| {
|
||||
assert!(!headless.buffer_store.read(cx).shared_buffers().is_empty())
|
||||
});
|
||||
do_search(&project, cx.clone()).await;
|
||||
|
||||
cx.update(|_| {
|
||||
drop(buffer);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
headless.update(server_cx, |headless, cx| {
|
||||
assert!(headless.buffer_store.read(cx).shared_buffers().is_empty())
|
||||
});
|
||||
|
||||
let first_response = receiver.next().await.unwrap();
|
||||
let SearchResult::Buffer { buffer, .. } = first_response else {
|
||||
panic!("incorrect result");
|
||||
};
|
||||
buffer.update(cx, |buffer, cx| {
|
||||
assert_eq!(
|
||||
buffer.file().unwrap().full_path(cx).to_string_lossy(),
|
||||
"project1/README.md"
|
||||
)
|
||||
});
|
||||
|
||||
assert!(receiver.next().await.is_none());
|
||||
do_search(&project, cx.clone()).await;
|
||||
}
|
||||
|
||||
fn init_logger() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue