Notify on opening WSL paths outside of wsl (#40195)

Closes #27340

Release Notes:

- N/A

---------

Co-authored-by: John Tur <john-tur@outlook.com>
This commit is contained in:
Julia Ryan
2025-10-25 01:44:32 +00:00
committed by GitHub
co-authored by John Tur
parent 1dffdea27c
commit 7433d85458
11 changed files with 250 additions and 72 deletions
@@ -102,6 +102,33 @@ pub fn init(cx: &mut App) {
});
});
#[cfg(target_os = "windows")]
cx.on_action(|open_wsl: &remote::OpenWslPath, cx| {
let open_wsl = open_wsl.clone();
with_active_or_new_workspace(cx, move |workspace, window, cx| {
let fs = workspace.project().read(cx).fs().clone();
add_wsl_distro(fs, &open_wsl.distro, cx);
let open_options = OpenOptions {
replace_window: window.window_handle().downcast::<Workspace>(),
..Default::default()
};
let app_state = workspace.app_state().clone();
cx.spawn_in(window, async move |_, cx| {
open_remote_project(
RemoteConnectionOptions::Wsl(open_wsl.distro.clone()),
open_wsl.paths,
app_state,
open_options,
cx,
)
.await
})
.detach();
});
});
cx.on_action(|open_recent: &OpenRecent, cx| {
let create_new_window = open_recent.create_new_window;
with_active_or_new_workspace(cx, move |workspace, window, cx| {
@@ -136,6 +163,38 @@ pub fn init(cx: &mut App) {
cx.observe_new(DisconnectedOverlay::register).detach();
}
#[cfg(target_os = "windows")]
pub fn add_wsl_distro(
fs: Arc<dyn project::Fs>,
connection_options: &remote::WslConnectionOptions,
cx: &App,
) {
use gpui::ReadGlobal;
use settings::SettingsStore;
let distro_name = SharedString::from(&connection_options.distro_name);
let user = connection_options.user.clone();
SettingsStore::global(cx).update_settings_file(fs, move |setting, _| {
let connections = setting
.remote
.wsl_connections
.get_or_insert(Default::default());
if !connections
.iter()
.any(|conn| conn.distro_name == distro_name && conn.user == user)
{
use std::collections::BTreeSet;
connections.push(settings::WslConnection {
distro_name,
user,
projects: BTreeSet::new(),
})
}
});
}
pub struct RecentProjects {
pub picker: Entity<Picker<RecentProjectsDelegate>>,
rem_width: f32,
+28 -47
View File
@@ -794,28 +794,34 @@ impl RemoteServerProjects {
let wsl_picker = picker.clone();
let creating = cx.spawn_in(window, async move |this, cx| {
match connection.await {
Some(Some(client)) => this
.update_in(cx, |this, window, cx| {
telemetry::event!("WSL Distro Added");
this.retained_connections.push(client);
this.add_wsl_distro(connection_options, cx);
this.mode = Mode::default_mode(&BTreeSet::new(), cx);
this.focus_handle(cx).focus(window);
cx.notify()
})
.log_err(),
_ => this
.update(cx, |this, cx| {
this.mode = Mode::AddWslDistro(AddWslDistro {
picker: wsl_picker,
connection_prompt: None,
_creating: None,
});
cx.notify()
})
.log_err(),
};
()
Some(Some(client)) => this.update_in(cx, |this, window, cx| {
telemetry::event!("WSL Distro Added");
this.retained_connections.push(client);
let Some(fs) = this
.workspace
.read_with(cx, |workspace, cx| {
workspace.project().read(cx).fs().clone()
})
.log_err()
else {
return;
};
crate::add_wsl_distro(fs, &connection_options, cx);
this.mode = Mode::default_mode(&BTreeSet::new(), cx);
this.focus_handle(cx).focus(window);
cx.notify();
}),
_ => this.update(cx, |this, cx| {
this.mode = Mode::AddWslDistro(AddWslDistro {
picker: wsl_picker,
connection_prompt: None,
_creating: None,
});
cx.notify();
}),
}
.log_err();
});
self.mode = Mode::AddWslDistro(AddWslDistro {
@@ -1415,31 +1421,6 @@ impl RemoteServerProjects {
});
}
#[cfg(target_os = "windows")]
fn add_wsl_distro(
&mut self,
connection_options: remote::WslConnectionOptions,
cx: &mut Context<Self>,
) {
self.update_settings_file(cx, move |setting, _| {
let connections = setting.wsl_connections.get_or_insert(Default::default());
let distro_name = SharedString::from(connection_options.distro_name);
let user = connection_options.user;
if !connections
.iter()
.any(|conn| conn.distro_name == distro_name && conn.user == user)
{
connections.push(settings::WslConnection {
distro_name,
user,
projects: BTreeSet::new(),
})
}
});
}
fn delete_wsl_distro(&mut self, server: WslServerIndex, cx: &mut Context<Self>) {
self.update_settings_file(cx, move |setting, _| {
if let Some(connections) = setting.wsl_connections.as_mut() {