Skip to content

Commit 70e0e53

Browse files
Inovviamaxdeviant
andauthored
Add workaround for leading / on Windows paths (#23)
This is based on zed-extensions/astro#5 which addresses zed-industries/zed#20559 so that svelte users on windows can also use the extension. Credits to @maxdeviant for the original astro fix --------- Co-authored-by: Marshall Bowers <git@maxdeviant.com>
1 parent 1ee0706 commit 70e0e53

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/svelte.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ impl zed::Extension for SvelteExtension {
7070
Ok(zed::Command {
7171
command: zed::node_binary_path()?,
7272
args: vec![
73-
env::current_dir()
74-
.unwrap()
73+
zed_ext::sanitize_windows_path(env::current_dir().unwrap())
7574
.join(&server_path)
7675
.to_string_lossy()
7776
.to_string(),
@@ -122,3 +121,25 @@ impl zed::Extension for SvelteExtension {
122121
}
123122

124123
zed::register_extension!(SvelteExtension);
124+
125+
/// Extensions to the Zed extension API that have not yet stabilized.
126+
mod zed_ext {
127+
/// Sanitizes the given path to remove the leading `/` on Windows.
128+
///
129+
/// On macOS and Linux this is a no-op.
130+
///
131+
/// This is a workaround for https://github.com/bytecodealliance/wasmtime/issues/10415.
132+
pub fn sanitize_windows_path(path: std::path::PathBuf) -> std::path::PathBuf {
133+
use zed_extension_api::{current_platform, Os};
134+
135+
let (os, _arch) = current_platform();
136+
match os {
137+
Os::Mac | Os::Linux => path,
138+
Os::Windows => path
139+
.to_string_lossy()
140+
.to_string()
141+
.trim_start_matches('/')
142+
.into(),
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)