Allow opening a local folder inside WSL (#38335)

This PR adds an option to allow opening local folders inside WSL
containers. (wsl_actions::OpenFolderInWsl). It is accessible via the
command palette and should be available to keybind.

- [x] Open wsl from open remote
- [x] Open local folder in wsl action
- [ ] Open wsl shortcut (shortcuts to open remote)

Release Notes:

- N/A
This commit is contained in:
localcc
2025-09-17 15:39:47 +00:00
committed by GitHub
parent f3b8c619e3
commit 4a7784cf67
7 changed files with 397 additions and 180 deletions
+21
View File
@@ -65,6 +65,7 @@ pub trait PathExt {
.with_context(|| format!("Invalid WTF-8 sequence: {bytes:?}"))
}
}
fn local_to_wsl(&self) -> Option<PathBuf>;
}
impl<T: AsRef<Path>> PathExt for T {
@@ -118,6 +119,26 @@ impl<T: AsRef<Path>> PathExt for T {
self.as_ref().to_string_lossy().to_string()
}
}
/// Converts a local path to one that can be used inside of WSL.
/// Returns `None` if the path cannot be converted into a WSL one (network share).
fn local_to_wsl(&self) -> Option<PathBuf> {
let mut new_path = PathBuf::new();
for component in self.as_ref().components() {
match component {
std::path::Component::Prefix(prefix) => {
let drive_letter = prefix.as_os_str().to_string_lossy().to_lowercase();
let drive_letter = drive_letter.strip_suffix(':')?;
new_path.push(format!("/mnt/{}", drive_letter));
}
std::path::Component::RootDir => {}
_ => new_path.push(component),
}
}
Some(new_path)
}
}
/// In memory, this is identical to `Path`. On non-Windows conversions to this type are no-ops. On