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:
@@ -1348,28 +1348,10 @@ impl WorkspaceDb {
|
||||
}
|
||||
|
||||
let has_wsl_path = if cfg!(windows) {
|
||||
fn is_wsl_path(path: &PathBuf) -> bool {
|
||||
use std::path::{Component, Prefix};
|
||||
|
||||
path.components()
|
||||
.next()
|
||||
.and_then(|component| match component {
|
||||
Component::Prefix(prefix) => Some(prefix),
|
||||
_ => None,
|
||||
})
|
||||
.and_then(|prefix| match prefix.kind() {
|
||||
Prefix::UNC(server, _) => Some(server),
|
||||
Prefix::VerbatimUNC(server, _) => Some(server),
|
||||
_ => None,
|
||||
})
|
||||
.map(|server| {
|
||||
let server_str = server.to_string_lossy();
|
||||
server_str == "wsl.localhost" || server_str == "wsl$"
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
paths.paths().iter().any(|path| is_wsl_path(path))
|
||||
paths
|
||||
.paths()
|
||||
.iter()
|
||||
.any(|path| util::paths::WslPath::from_path(path).is_some())
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
@@ -7318,6 +7318,10 @@ pub fn open_paths(
|
||||
let mut existing = None;
|
||||
let mut best_match = None;
|
||||
let mut open_visible = OpenVisible::All;
|
||||
#[cfg(target_os = "windows")]
|
||||
let wsl_path = abs_paths
|
||||
.iter()
|
||||
.find_map(|p| util::paths::WslPath::from_path(p));
|
||||
|
||||
cx.spawn(async move |cx| {
|
||||
if open_options.open_new_workspace != Some(true) {
|
||||
@@ -7381,7 +7385,7 @@ pub fn open_paths(
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(existing) = existing {
|
||||
let result = if let Some(existing) = existing {
|
||||
let open_task = existing
|
||||
.update(cx, |workspace, window, cx| {
|
||||
window.activate_window();
|
||||
@@ -7418,7 +7422,37 @@ pub fn open_paths(
|
||||
)
|
||||
})?
|
||||
.await
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
if let Some(util::paths::WslPath{distro, path}) = wsl_path
|
||||
&& let Ok((workspace, _)) = &result
|
||||
{
|
||||
workspace
|
||||
.update(cx, move |workspace, _window, cx| {
|
||||
struct OpenInWsl;
|
||||
workspace.show_notification(NotificationId::unique::<OpenInWsl>(), cx, move |cx| {
|
||||
let display_path = util::markdown::MarkdownInlineCode(&path.to_string_lossy());
|
||||
let msg = format!("{display_path} is inside a WSL filesystem, some features may not work unless you open it with WSL remote");
|
||||
cx.new(move |cx| {
|
||||
MessageNotification::new(msg, cx)
|
||||
.primary_message("Open in WSL")
|
||||
.primary_icon(IconName::FolderOpen)
|
||||
.primary_on_click(move |window, cx| {
|
||||
window.dispatch_action(Box::new(remote::OpenWslPath {
|
||||
distro: remote::WslConnectionOptions {
|
||||
distro_name: distro.clone(),
|
||||
user: None,
|
||||
},
|
||||
paths: vec![path.clone().into()],
|
||||
}), cx)
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user