From 3bce60127f4679f07b60cf3d64dad6b4204bad4c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 16 Jan 2023 17:33:44 +0100 Subject: [PATCH] Merge pull request #2030 from zed-industries/fix-typescript-lsp Fix error when running TypeScript language server after version 3.0.2 --- crates/zed/src/languages/installation.rs | 4 ++++ crates/zed/src/languages/typescript.rs | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/zed/src/languages/installation.rs b/crates/zed/src/languages/installation.rs index 40edbb88d7..c5aff17e56 100644 --- a/crates/zed/src/languages/installation.rs +++ b/crates/zed/src/languages/installation.rs @@ -37,6 +37,8 @@ pub(crate) struct GithubReleaseAsset { pub async fn npm_package_latest_version(name: &str) -> Result { let output = smol::process::Command::new("npm") + .args(["-fetch-retry-mintimeout", "2000"]) + .args(["-fetch-retry-maxtimeout", "5000"]) .args(["info", name, "--json"]) .output() .await @@ -60,6 +62,8 @@ pub async fn npm_install_packages( directory: &Path, ) -> Result<()> { let output = smol::process::Command::new("npm") + .args(["-fetch-retry-mintimeout", "2000"]) + .args(["-fetch-retry-maxtimeout", "5000"]) .arg("install") .arg("--prefix") .arg(directory) diff --git a/crates/zed/src/languages/typescript.rs b/crates/zed/src/languages/typescript.rs index f54b09ceda..01b62577ad 100644 --- a/crates/zed/src/languages/typescript.rs +++ b/crates/zed/src/languages/typescript.rs @@ -12,7 +12,8 @@ use util::ResultExt; pub struct TypeScriptLspAdapter; impl TypeScriptLspAdapter { - const BIN_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.js"; + const OLD_BIN_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.js"; + const NEW_BIN_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs"; } struct Versions { @@ -57,7 +58,7 @@ impl LspAdapter for TypeScriptLspAdapter { fs::create_dir_all(&version_dir) .await .context("failed to create version directory")?; - let binary_path = version_dir.join(Self::BIN_PATH); + let binary_path = version_dir.join(Self::NEW_BIN_PATH); if fs::metadata(&binary_path).await.is_err() { npm_install_packages( @@ -98,9 +99,12 @@ impl LspAdapter for TypeScriptLspAdapter { } } let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?; - let bin_path = last_version_dir.join(Self::BIN_PATH); - if bin_path.exists() { - Ok(bin_path) + let old_bin_path = last_version_dir.join(Self::OLD_BIN_PATH); + let new_bin_path = last_version_dir.join(Self::NEW_BIN_PATH); + if new_bin_path.exists() { + Ok(new_bin_path) + } else if old_bin_path.exists() { + Ok(old_bin_path) } else { Err(anyhow!( "missing executable in directory {:?}",