Skip to content

Commit 7f14ab2

Browse files
authored
copilot: Ensure minimum Node version (#38945)
Closes #38918 Release Notes: - N/A
1 parent 5ee73d3 commit 7f14ab2

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/copilot/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ node_runtime.workspace = true
4343
parking_lot.workspace = true
4444
paths.workspace = true
4545
project.workspace = true
46+
semver.workspace = true
4647
serde.workspace = true
4748
serde_json.workspace = true
4849
settings.workspace = true

crates/copilot/src/copilot.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use node_runtime::{NodeRuntime, VersionStrategy};
2525
use parking_lot::Mutex;
2626
use project::DisableAiSettings;
2727
use request::StatusNotification;
28+
use semver::Version;
2829
use serde_json::json;
2930
use settings::Settings;
3031
use settings::SettingsStore;
@@ -485,6 +486,8 @@ impl Copilot {
485486
let start_language_server = async {
486487
let server_path = get_copilot_lsp(fs, node_runtime.clone()).await?;
487488
let node_path = node_runtime.binary_path().await?;
489+
ensure_node_version_for_copilot(&node_path).await?;
490+
488491
let arguments: Vec<OsString> = vec![server_path.into(), "--stdio".into()];
489492
let binary = LanguageServerBinary {
490493
path: node_path,
@@ -1161,6 +1164,44 @@ async fn clear_copilot_config_dir() {
11611164
remove_matching(copilot_chat::copilot_chat_config_dir(), |_| true).await
11621165
}
11631166

1167+
async fn ensure_node_version_for_copilot(node_path: &Path) -> anyhow::Result<()> {
1168+
const MIN_COPILOT_NODE_VERSION: Version = Version::new(20, 8, 0);
1169+
1170+
log::info!("Checking Node.js version for Copilot at: {:?}", node_path);
1171+
1172+
let output = util::command::new_smol_command(node_path)
1173+
.arg("--version")
1174+
.output()
1175+
.await
1176+
.with_context(|| format!("checking Node.js version at {:?}", node_path))?;
1177+
1178+
if !output.status.success() {
1179+
anyhow::bail!(
1180+
"failed to run node --version for Copilot. stdout: {}, stderr: {}",
1181+
String::from_utf8_lossy(&output.stdout),
1182+
String::from_utf8_lossy(&output.stderr),
1183+
);
1184+
}
1185+
1186+
let version_str = String::from_utf8_lossy(&output.stdout);
1187+
let version = Version::parse(version_str.trim().trim_start_matches('v'))
1188+
.with_context(|| format!("parsing Node.js version from '{}'", version_str.trim()))?;
1189+
1190+
if version < MIN_COPILOT_NODE_VERSION {
1191+
anyhow::bail!(
1192+
"GitHub Copilot language server requires Node.js {MIN_COPILOT_NODE_VERSION} or later, but found {version}. \
1193+
Please update your Node.js version or configure a different Node.js path in settings."
1194+
);
1195+
}
1196+
1197+
log::info!(
1198+
"Node.js version {} meets Copilot requirements (>= {})",
1199+
version,
1200+
MIN_COPILOT_NODE_VERSION
1201+
);
1202+
Ok(())
1203+
}
1204+
11641205
async fn get_copilot_lsp(fs: Arc<dyn Fs>, node_runtime: NodeRuntime) -> anyhow::Result<PathBuf> {
11651206
const PACKAGE_NAME: &str = "@github/copilot-language-server";
11661207
const SERVER_PATH: &str =

0 commit comments

Comments
 (0)