Maintain remote buffers via UpdateBufferFile
messages sent by host
This commit is contained in:
parent
da13d028a3
commit
4372fe1ed0
4 changed files with 115 additions and 23 deletions
|
@ -77,6 +77,7 @@ impl Server {
|
|||
.add_handler(Server::open_buffer)
|
||||
.add_handler(Server::close_buffer)
|
||||
.add_handler(Server::update_buffer)
|
||||
.add_handler(Server::update_buffer_file)
|
||||
.add_handler(Server::buffer_saved)
|
||||
.add_handler(Server::save_buffer)
|
||||
.add_handler(Server::format_buffer)
|
||||
|
@ -704,6 +705,22 @@ impl Server {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_buffer_file(
|
||||
self: Arc<Server>,
|
||||
request: TypedEnvelope<proto::UpdateBufferFile>,
|
||||
) -> tide::Result<()> {
|
||||
let receiver_ids = self
|
||||
.state()
|
||||
.project_connection_ids(request.payload.project_id, request.sender_id)
|
||||
.ok_or_else(|| anyhow!(NO_SUCH_PROJECT))?;
|
||||
broadcast(request.sender_id, receiver_ids, |connection_id| {
|
||||
self.peer
|
||||
.forward_send(request.sender_id, connection_id, request.payload.clone())
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn buffer_saved(
|
||||
self: Arc<Server>,
|
||||
request: TypedEnvelope<proto::BufferSaved>,
|
||||
|
@ -1470,9 +1487,7 @@ mod tests {
|
|||
.condition(&mut cx_a, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
|
||||
.await;
|
||||
buffer_b
|
||||
.condition(&mut cx_b, |buf, _| {
|
||||
dbg!(buf.text()) == "i-am-c, i-am-b, i-am-a"
|
||||
})
|
||||
.condition(&mut cx_b, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
|
||||
.await;
|
||||
buffer_c
|
||||
.condition(&mut cx_c, |buf, _| buf.text() == "i-am-c, i-am-b, i-am-a")
|
||||
|
@ -1490,7 +1505,10 @@ mod tests {
|
|||
buffer_b.read_with(&cx_b, |buf, _| assert!(!buf.is_dirty()));
|
||||
buffer_c.condition(&cx_c, |buf, _| !buf.is_dirty()).await;
|
||||
|
||||
// Make changes on host's file system, see those changes on the guests.
|
||||
// Make changes on host's file system, see those changes on guest worktrees.
|
||||
fs.rename("/a/file1".as_ref(), "/a/file1-renamed".as_ref())
|
||||
.await
|
||||
.unwrap();
|
||||
fs.rename("/a/file2".as_ref(), "/a/file3".as_ref())
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -1498,18 +1516,29 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
worktree_a
|
||||
.condition(&cx_a, |tree, _| tree.file_count() == 4)
|
||||
.await;
|
||||
worktree_b
|
||||
.condition(&cx_b, |tree, _| tree.file_count() == 4)
|
||||
.await;
|
||||
worktree_c
|
||||
.condition(&cx_c, |tree, _| tree.file_count() == 4)
|
||||
.await;
|
||||
worktree_a.read_with(&cx_a, |tree, _| {
|
||||
assert_eq!(
|
||||
tree.paths()
|
||||
.map(|p| p.to_string_lossy())
|
||||
.collect::<Vec<_>>(),
|
||||
&[".zed.toml", "file1-renamed", "file3", "file4"]
|
||||
)
|
||||
});
|
||||
worktree_b.read_with(&cx_b, |tree, _| {
|
||||
assert_eq!(
|
||||
tree.paths()
|
||||
.map(|p| p.to_string_lossy())
|
||||
.collect::<Vec<_>>(),
|
||||
&[".zed.toml", "file1", "file3", "file4"]
|
||||
&[".zed.toml", "file1-renamed", "file3", "file4"]
|
||||
)
|
||||
});
|
||||
worktree_c.read_with(&cx_c, |tree, _| {
|
||||
|
@ -1517,9 +1546,26 @@ mod tests {
|
|||
tree.paths()
|
||||
.map(|p| p.to_string_lossy())
|
||||
.collect::<Vec<_>>(),
|
||||
&[".zed.toml", "file1", "file3", "file4"]
|
||||
&[".zed.toml", "file1-renamed", "file3", "file4"]
|
||||
)
|
||||
});
|
||||
|
||||
// Ensure buffer files are updated as well.
|
||||
buffer_a
|
||||
.condition(&cx_a, |buf, _| {
|
||||
buf.file().unwrap().path().to_str() == Some("file1-renamed")
|
||||
})
|
||||
.await;
|
||||
buffer_b
|
||||
.condition(&cx_b, |buf, _| {
|
||||
buf.file().unwrap().path().to_str() == Some("file1-renamed")
|
||||
})
|
||||
.await;
|
||||
buffer_c
|
||||
.condition(&cx_c, |buf, _| {
|
||||
buf.file().unwrap().path().to_str() == Some("file1-renamed")
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue