Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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))?;
.map_err(|err| format!("failed to get editor services: {err}"))?;

let command = format!(
"Import-Module ( \
Expand Down Expand Up @@ -61,13 +61,13 @@ impl zed::Extension for PowerShellExtension {
impl PowerShellExtension {
fn powershell_binary_path(&mut self, worktree: &zed::Worktree) -> Result<String> {
let pwsh_path = match &self.powershell_bin {
Some(path) if fs::metadata(path).map_or(false, |stat| stat.is_file()) => path.clone(),
Some(path) if fs::metadata(path).is_ok_and(|stat| stat.is_file()) => path.clone(),
Some(path) => worktree
.which(path.clone().as_str())
.ok_or_else(|| "PowerShell must be installed for PowerShell Extension")?,
.ok_or("PowerShell must be installed for PowerShell Extension")?,
None => worktree
.which("pwsh")
.ok_or_else(|| "PowerShell must be installed for PowerShell Extension")?,
.ok_or("PowerShell must be installed for PowerShell Extension")?,
};
self.powershell_bin = Some(pwsh_path.clone());
Ok(pwsh_path)
Expand All @@ -94,23 +94,23 @@ impl PowerShellExtension {
.assets
.iter()
.find(|asset| asset.name == "PowerShellEditorServices.zip")
.ok_or_else(|| format!("no PowerShellEditorServices.zip found"))?;
.ok_or_else(|| "no PowerShellEditorServices.zip found".to_string())?;

let version_dir = format!("powershell-es-{}", release.version);
let lsp_path = format!("{version_dir}/PowerShellEditorServices/Start-EditorServices.ps1");

if !fs::metadata(&lsp_path).map_or(false, |stat| stat.is_file()) {
if !fs::metadata(&lsp_path).is_ok_and(|stat| stat.is_file()) {
// Download the asset
zed::set_language_server_installation_status(
&language_server_id,
language_server_id,
&zed::LanguageServerInstallationStatus::Downloading,
);
zed::download_file(
&asset.download_url,
&version_dir,
zed::DownloadedFileType::Zip,
)
.map_err(|err| format!("download error {}", err))?;
.map_err(|err| format!("download error {err}"))?;

// Ensure the binary exists
let entries =
Expand Down