extension_host: Use the more permissive RelPath constructor for paths from extensions (#38965)

Closes #38922 

Release Notes:

- N/A

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
This commit is contained in:
Cole Miller
2025-09-27 09:20:42 -04:00
committed by GitHub
co-authored by Jakub Konka
parent e13b88e4bd
commit 687e22b4c3
2 changed files with 23 additions and 12 deletions
@@ -16,6 +16,7 @@ use std::{
path::{Path, PathBuf},
sync::{Arc, OnceLock},
};
use util::paths::PathStyle;
use util::rel_path::RelPath;
use util::{archive::extract_zip, fs::make_file_executable, maybe};
use wasmtime::component::{Linker, Resource};
@@ -422,12 +423,16 @@ impl ExtensionImports for WasmState {
) -> wasmtime::Result<Result<String, String>> {
self.on_main_thread(|cx| {
async move {
let location = location.as_ref().and_then(|location| {
Some(::settings::SettingsLocation {
worktree_id: WorktreeId::from_proto(location.worktree_id),
path: RelPath::unix(&location.path).ok()?,
})
let path = location.as_ref().and_then(|location| {
RelPath::new(Path::new(&location.path), PathStyle::Posix).ok()
});
let location = path
.as_ref()
.zip(location.as_ref())
.map(|(path, location)| ::settings::SettingsLocation {
worktree_id: WorktreeId::from_proto(location.worktree_id),
path,
});
cx.update(|cx| match category.as_str() {
"language" => {
@@ -31,7 +31,9 @@ use std::{
};
use task::{SpawnInTerminal, ZedDebugConfig};
use url::Url;
use util::{archive::extract_zip, fs::make_file_executable, maybe, rel_path::RelPath};
use util::{
archive::extract_zip, fs::make_file_executable, maybe, paths::PathStyle, rel_path::RelPath,
};
use wasmtime::component::{Linker, Resource};
pub const MIN_VERSION: SemanticVersion = SemanticVersion::new(0, 6, 0);
@@ -564,7 +566,7 @@ impl HostWorktree for WasmState {
) -> wasmtime::Result<Result<String, String>> {
let delegate = self.table.get(&delegate)?;
Ok(delegate
.read_text_file(RelPath::unix(&path)?)
.read_text_file(&RelPath::new(Path::new(&path), PathStyle::Posix)?)
.await
.map_err(|error| error.to_string()))
}
@@ -914,12 +916,16 @@ impl ExtensionImports for WasmState {
) -> wasmtime::Result<Result<String, String>> {
self.on_main_thread(|cx| {
async move {
let location = location.as_ref().and_then(|location| {
Some(::settings::SettingsLocation {
worktree_id: WorktreeId::from_proto(location.worktree_id),
path: RelPath::unix(&location.path).ok()?,
})
let path = location.as_ref().and_then(|location| {
RelPath::new(Path::new(&location.path), PathStyle::Posix).ok()
});
let location = path
.as_ref()
.zip(location.as_ref())
.map(|(path, location)| ::settings::SettingsLocation {
worktree_id: WorktreeId::from_proto(location.worktree_id),
path,
});
cx.update(|cx| match category.as_str() {
"language" => {