From 95c1da05e699f862c0d48e37f7a40e171f0169e3 Mon Sep 17 00:00:00 2001 From: Blast Date: Wed, 23 Jul 2025 22:14:18 +0300 Subject: [PATCH 1/3] fix: remove redundant slash prefix on windows --- src/powershell.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/powershell.rs b/src/powershell.rs index 5798f76..bef0099 100644 --- a/src/powershell.rs +++ b/src/powershell.rs @@ -1,5 +1,5 @@ use std::fs; -use std::path; +use std::path::{self, Path}; use zed_extension_api::{self as zed, Result}; struct PowerShellExtension { @@ -30,19 +30,29 @@ impl zed::Extension for PowerShellExtension { .map_err(|err| format!("failed to get editor services: {}", err))?; let command = format!( - "Import-Module ( \ - Join-Path '{bundle_path}' 'PowerShellEditorServices/PowerShellEditorServices.psd1' \ - ); \ - Start-EditorServices \ - -Stdio \ - -SessionDetailsPath '{bundle_path}/powershell-es.session.json' \ - -LogPath '{bundle_path}/logs' \ - -FeatureFlags @() \ - -AdditionalModules @() \ - -HostName zed \ - -HostProfileId 0 \ - -HostVersion 1.0.0 \ - -LogLevel Trace" + r#" + $Module = Join-Path "{0}" "PowerShellEditorServices" "PowerShellEditorServices.psd1" + $SessionDetails = Join-Path "{0}" "powershell-es.session.json" + $Log = Join-Path "{0}" "logs" + + Import-Module $Module + + Start-EditorServices ` + -Stdio ` + -SessionDetailsPath $SessionDetails ` + -LogPath $Log ` + -FeatureFlags @() ` + -AdditionalModules @() ` + -HostName "zed" ` + -HostProfileId 0 ` + -HostVersion "1.0.0" ` + -LogLevel "Trace" + "#, + Path::new(&bundle_path) + .to_str() + .ok_or("invalid unicode in bundle_path")? + .strip_prefix('/') + .unwrap_or_else(|| bundle_path.as_str()) ); Ok(zed::Command { From 636b3198a0aed0ead5786d4b359418826437f1ec Mon Sep 17 00:00:00 2001 From: Blast Date: Sat, 26 Jul 2025 21:14:09 +0300 Subject: [PATCH 2/3] normalize bundle_path on windows --- src/powershell.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/powershell.rs b/src/powershell.rs index bef0099..f6cabab 100644 --- a/src/powershell.rs +++ b/src/powershell.rs @@ -1,7 +1,19 @@ use std::fs; -use std::path::{self, Path}; +use std::path::{self}; use zed_extension_api::{self as zed, Result}; +fn normalize_bundle_path(path: String) -> String { + if let Some(stripped_path) = path.strip_prefix('/') { + if stripped_path.len() > 2 + && stripped_path.as_bytes()[0].is_ascii_alphabetic() + && stripped_path.as_bytes()[1] == b':' + { + return stripped_path.to_string(); + } + } + path +} + struct PowerShellExtension { /// The PowerShell binary, default to `pwsh`. // TODO: allow to configure via Zed settings. @@ -28,12 +40,13 @@ impl zed::Extension for PowerShellExtension { let bundle_path = self .language_server_path(language_server_id) .map_err(|err| format!("failed to get editor services: {}", err))?; + let bundle_path = normalize_bundle_path(bundle_path); let command = format!( r#" - $Module = Join-Path "{0}" "PowerShellEditorServices" "PowerShellEditorServices.psd1" - $SessionDetails = Join-Path "{0}" "powershell-es.session.json" - $Log = Join-Path "{0}" "logs" + $Module = Join-Path "{bundle_path}" "PowerShellEditorServices" "PowerShellEditorServices.psd1" + $SessionDetails = Join-Path "{bundle_path}" "powershell-es.session.json" + $Log = Join-Path "{bundle_path}" "logs" Import-Module $Module @@ -48,11 +61,6 @@ impl zed::Extension for PowerShellExtension { -HostVersion "1.0.0" ` -LogLevel "Trace" "#, - Path::new(&bundle_path) - .to_str() - .ok_or("invalid unicode in bundle_path")? - .strip_prefix('/') - .unwrap_or_else(|| bundle_path.as_str()) ); Ok(zed::Command { From 906774b633f75d082138180cd9cc4edc35e986e1 Mon Sep 17 00:00:00 2001 From: Blast Date: Sat, 26 Jul 2025 21:32:57 +0300 Subject: [PATCH 3/3] clean up imports --- src/powershell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/powershell.rs b/src/powershell.rs index f6cabab..4eab5ad 100644 --- a/src/powershell.rs +++ b/src/powershell.rs @@ -1,5 +1,5 @@ use std::fs; -use std::path::{self}; +use std::path; use zed_extension_api::{self as zed, Result}; fn normalize_bundle_path(path: String) -> String {