Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix SSH config host refresh in the remote projects picker (#65246)
Ege Cem Kırcıdc000222a978
diff --git a/crates/recent_projects/src/remote_servers.rs b/crates/recent_projects/src/remote_servers.rsindex 9861d728706..1ae2f30de57 100644--- a/crates/recent_projects/src/remote_servers.rs+++ b/crates/recent_projects/src/remote_servers.rs@@ -1011,6 +1011,7 @@ impl RemoteServerPickerDelegate {};Some(h_flex()+ .debug_selector(|| format!("remote-server-{}", server.display_host())).w_full().pt_1().px_3()@@ -1504,7 +1505,7 @@ impl RemoteServerProjects {});let mut read_ssh_config = RemoteSettings::get_global(cx).read_ssh_config;let ssh_config_updates = if read_ssh_config {- spawn_ssh_config_watch(fs.clone(), cx)+ spawn_ssh_config_watch(fs.clone(), window, cx)} else {Task::ready(())};@@ -1515,7 +1516,8 @@ impl RemoteServerProjects {if read_ssh_config != new_read_ssh_config {read_ssh_config = new_read_ssh_config;if read_ssh_config {- recent_projects.ssh_config_updates = spawn_ssh_config_watch(fs.clone(), cx);+ recent_projects.ssh_config_updates =+ spawn_ssh_config_watch(fs.clone(), window, cx);} else {recent_projects.ssh_config_servers.clear();recent_projects.ssh_config_updates = Task::ready(());@@ -2971,7 +2973,11 @@ impl RemoteServerProjects {}}-fn spawn_ssh_config_watch(fs: Arc<dyn Fs>, cx: &Context<RemoteServerProjects>) -> Task<()> {+fn spawn_ssh_config_watch(+ fs: Arc<dyn Fs>,+ window: &mut Window,+ cx: &Context<RemoteServerProjects>,+) -> Task<()> {enum ConfigSource {User(String),Global(String),@@ -3003,7 +3009,7 @@ fn spawn_ssh_config_watch(fs: Arc<dyn Fs>, cx: &Context<RemoteServerProjects>) -// Combine into a single stream so that only one is parsed at once.let mut merged_stream = futures::stream::select_all(streams);- cx.spawn(async move |remote_server_projects, cx| {+ cx.spawn_in(window, async move |remote_server_projects, cx| {let _tasks = tasks; // Keeps the background watchers alivelet mut global_hosts = BTreeSet::default();let mut user_hosts = BTreeSet::default();@@ -3020,21 +3026,13 @@ fn spawn_ssh_config_watch(fs: Arc<dyn Fs>, cx: &Context<RemoteServerProjects>) -// Sync to Modelif remote_server_projects- .update(cx, |project, cx| {+ .update_in(cx, |project, window, cx| {project.ssh_config_servers = global_hosts.iter().chain(user_hosts.iter()).map(SharedString::from).collect();- let ssh_config_servers = project.ssh_config_servers.clone();- let (has_open_project, is_local) =- RemoteServerProjects::workspace_flags(&project.workspace, cx);- project.default_picker.update(cx, |picker, cx| {- picker- .delegate- .reload(&ssh_config_servers, has_open_project, is_local, cx);- cx.notify();- });+ project.refresh_default_picker(window, cx);cx.notify();}).is_err()@@ -3147,7 +3145,7 @@ mod filter_tests {}#[cfg(test)]-mod create_host_tests {+mod tests {use super::*;use gpui::TestAppContext;@@ -3160,6 +3158,102 @@ mod create_host_tests {})}+ #[gpui::test]+ async fn test_ssh_config_changes_refresh_rendered_hosts(cx: &mut TestAppContext) {+ let app_state = init_test(cx);+ let fs = app_state.fs.as_fake();+ let config_path = user_ssh_config_file();+ fs.create_dir(config_path.parent().expect("SSH config has a parent"))+ .await+ .expect("create SSH config directory");+ fs.insert_file(&config_path, Vec::new()).await;++ let project = Project::test(fs.clone(), [], cx).await;+ let (multi_workspace, cx) = cx.add_window_view(|window, cx| {+ let workspace = cx.new(|cx| Workspace::test_new(project, window, cx));+ MultiWorkspace::new(workspace, window, cx)+ });+ let workspace =+ multi_workspace.read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone());+ workspace.update_in(cx, |workspace, window, cx| {+ let weak = cx.weak_entity();+ workspace.toggle_modal(window, cx, |window, cx| {+ RemoteServerProjects::new(false, fs.clone(), window, weak, cx)+ });+ });+ cx.run_until_parked();++ // Settle the initial picker refresh before discovery changes its item count.+ fs.insert_file(&config_path, b"Host alpha beta\n".to_vec())+ .await;+ cx.run_until_parked();+ assert!(cx.debug_bounds("remote-server-alpha").is_some());+ assert!(cx.debug_bounds("remote-server-beta").is_some());++ fs.insert_file(&config_path, b"Host beta\n".to_vec()).await;+ cx.run_until_parked();+ assert!(cx.debug_bounds("remote-server-alpha").is_none());+ assert!(cx.debug_bounds("remote-server-beta").is_some());++ fs.insert_file(&config_path, Vec::new()).await;+ cx.run_until_parked();+ assert!(cx.debug_bounds("remote-server-beta").is_none());+ }++ #[gpui::test]+ async fn test_ssh_config_changes_refresh_filtered_hosts(cx: &mut TestAppContext) {+ let app_state = init_test(cx);+ let fs = app_state.fs.as_fake();+ let config_path = user_ssh_config_file();+ fs.create_dir(config_path.parent().expect("SSH config has a parent"))+ .await+ .expect("create SSH config directory");+ fs.insert_file(&config_path, b"Host beta\n".to_vec()).await;++ let project = Project::test(fs.clone(), [], cx).await;+ let (multi_workspace, cx) = cx.add_window_view(|window, cx| {+ let workspace = cx.new(|cx| Workspace::test_new(project, window, cx));+ MultiWorkspace::new(workspace, window, cx)+ });+ let workspace =+ multi_workspace.read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone());+ let modal = workspace.update_in(cx, |workspace, window, cx| {+ let weak = cx.weak_entity();+ workspace.toggle_modal(window, cx, |window, cx| {+ RemoteServerProjects::new(false, fs.clone(), window, weak, cx)+ });+ workspace+ .active_modal::<RemoteServerProjects>(cx)+ .expect("remote projects modal is open")+ });+ cx.run_until_parked();+ modal.update_in(cx, |modal, window, cx| {+ modal.default_picker.update(cx, |picker, cx| {+ picker.set_query("be", window, cx);+ });+ });+ cx.run_until_parked();+ assert!(cx.debug_bounds("remote-server-beta").is_some());++ fs.insert_file(&config_path, b"Host alpha beta berry\n".to_vec())+ .await;+ cx.run_until_parked();+ assert!(cx.debug_bounds("remote-server-alpha").is_none());+ assert!(cx.debug_bounds("remote-server-beta").is_some());+ assert!(cx.debug_bounds("remote-server-berry").is_some());++ fs.insert_file(&config_path, b"Host alpha berry\n".to_vec())+ .await;+ cx.run_until_parked();+ assert!(cx.debug_bounds("remote-server-alpha").is_none());+ assert!(cx.debug_bounds("remote-server-beta").is_none());+ assert!(cx.debug_bounds("remote-server-berry").is_some());+ assert_eq!(+ modal.read_with(cx, |modal, cx| modal.default_picker.read(cx).query(cx)),+ "be"+ );+ }+#[gpui::test]async fn test_create_host_from_ssh_config_returns_new_connection_index(cx: &mut TestAppContext,