Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
copilot: Ensure minimum Node version (#38945)
Smit Barmase7f14ab26ddb5
diff --git a/Cargo.lock b/Cargo.lockindex 5bbe2f880ba..a24c27144fe 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3696,6 +3696,7 @@ dependencies = ["paths","project","rpc",+ "semver","serde","serde_json","settings",diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.tomlindex 0fc119f3112..a0a49d6f25d 100644--- a/crates/copilot/Cargo.toml+++ b/crates/copilot/Cargo.toml@@ -43,6 +43,7 @@ node_runtime.workspace = trueparking_lot.workspace = truepaths.workspace = trueproject.workspace = true+semver.workspace = trueserde.workspace = trueserde_json.workspace = truesettings.workspace = truediff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rsindex 49753c3a6d9..ffcae93b40a 100644--- a/crates/copilot/src/copilot.rs+++ b/crates/copilot/src/copilot.rs@@ -25,6 +25,7 @@ use node_runtime::{NodeRuntime, VersionStrategy};use parking_lot::Mutex;use project::DisableAiSettings;use request::StatusNotification;+use semver::Version;use serde_json::json;use settings::Settings;use settings::SettingsStore;@@ -485,6 +486,8 @@ impl Copilot {let start_language_server = async {let server_path = get_copilot_lsp(fs, node_runtime.clone()).await?;let node_path = node_runtime.binary_path().await?;+ ensure_node_version_for_copilot(&node_path).await?;+let arguments: Vec<OsString> = vec![server_path.into(), "--stdio".into()];let binary = LanguageServerBinary {path: node_path,@@ -1161,6 +1164,44 @@ async fn clear_copilot_config_dir() {remove_matching(copilot_chat::copilot_chat_config_dir(), |_| true).await}+async fn ensure_node_version_for_copilot(node_path: &Path) -> anyhow::Result<()> {+ const MIN_COPILOT_NODE_VERSION: Version = Version::new(20, 8, 0);++ log::info!("Checking Node.js version for Copilot at: {:?}", node_path);++ let output = util::command::new_smol_command(node_path)+ .arg("--version")+ .output()+ .await+ .with_context(|| format!("checking Node.js version at {:?}", node_path))?;++ if !output.status.success() {+ anyhow::bail!(+ "failed to run node --version for Copilot. stdout: {}, stderr: {}",+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr),+ );+ }++ let version_str = String::from_utf8_lossy(&output.stdout);+ let version = Version::parse(version_str.trim().trim_start_matches('v'))+ .with_context(|| format!("parsing Node.js version from '{}'", version_str.trim()))?;++ if version < MIN_COPILOT_NODE_VERSION {+ anyhow::bail!(+ "GitHub Copilot language server requires Node.js {MIN_COPILOT_NODE_VERSION} or later, but found {version}. \+ Please update your Node.js version or configure a different Node.js path in settings."+ );+ }++ log::info!(+ "Node.js version {} meets Copilot requirements (>= {})",+ version,+ MIN_COPILOT_NODE_VERSION+ );+ Ok(())+}+async fn get_copilot_lsp(fs: Arc<dyn Fs>, node_runtime: NodeRuntime) -> anyhow::Result<PathBuf> {const PACKAGE_NAME: &str = "@github/copilot-language-server";const SERVER_PATH: &str =