From 5229cc75ac5d36a1329a52d8dd80fde761edcba7 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Thu, 18 Sep 2025 14:45:02 -0400 Subject: [PATCH] python: Install basedpyright if the basedpyright-langserver binary is missing (#38426) Potential fix for #38377 Release Notes: - N/A --------- Co-authored-by: Peter Tripp --- crates/language/src/language.rs | 5 +--- crates/languages/src/python.rs | 48 ++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 3c951e50ff231a72e284da743bb3e5d409eb9c5e..1e471cb03ffa4e887273513ff0053299f8b4b677 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -55,7 +55,7 @@ use std::{ str, sync::{ Arc, LazyLock, - atomic::{AtomicU64, AtomicUsize, Ordering::SeqCst}, + atomic::{AtomicUsize, Ordering::SeqCst}, }, }; use syntax_map::{QueryCursorHandle, SyntaxSnapshot}; @@ -168,7 +168,6 @@ pub struct CachedLspAdapter { pub disk_based_diagnostics_progress_token: Option, language_ids: HashMap, pub adapter: Arc, - pub reinstall_attempt_count: AtomicU64, cached_binary: ServerBinaryCache, } @@ -185,7 +184,6 @@ impl Debug for CachedLspAdapter { &self.disk_based_diagnostics_progress_token, ) .field("language_ids", &self.language_ids) - .field("reinstall_attempt_count", &self.reinstall_attempt_count) .finish_non_exhaustive() } } @@ -204,7 +202,6 @@ impl CachedLspAdapter { language_ids, adapter, cached_binary: Default::default(), - reinstall_attempt_count: AtomicU64::new(0), }) } diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index e0273250c91af8f437bff435d4a0f2f0c6467951..cacac5017ca486ff5711be58f6fb0e383f7b4250 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -1559,7 +1559,7 @@ impl LspInstaller for PyLspAdapter { util::command::new_smol_command(pip_path.as_path()) .arg("install") .arg("python-lsp-server") - .arg("-U") + .arg("--upgrade") .output() .await? .status @@ -1570,7 +1570,7 @@ impl LspInstaller for PyLspAdapter { util::command::new_smol_command(pip_path.as_path()) .arg("install") .arg("python-lsp-server[all]") - .arg("-U") + .arg("--upgrade") .output() .await? .status @@ -1581,7 +1581,7 @@ impl LspInstaller for PyLspAdapter { util::command::new_smol_command(pip_path) .arg("install") .arg("pylsp-mypy") - .arg("-U") + .arg("--upgrade") .output() .await? .status @@ -1589,6 +1589,10 @@ impl LspInstaller for PyLspAdapter { "pylsp-mypy installation failed" ); let pylsp = venv.join(BINARY_DIR).join("pylsp"); + ensure!( + delegate.which(pylsp.as_os_str()).await.is_some(), + "pylsp installation was incomplete" + ); Ok(LanguageServerBinary { path: pylsp, env: None, @@ -1603,6 +1607,7 @@ impl LspInstaller for PyLspAdapter { ) -> Option { let venv = self.base_venv(delegate).await.ok()?; let pylsp = venv.join(BINARY_DIR).join("pylsp"); + delegate.which(pylsp.as_os_str()).await?; Some(LanguageServerBinary { path: pylsp, env: None, @@ -1641,9 +1646,11 @@ impl BasedPyrightLspAdapter { .arg("venv") .arg("basedpyright-venv") .current_dir(work_dir) - .spawn()? + .spawn() + .context("spawning child")? .output() - .await?; + .await + .context("getting child output")?; } Ok(path.into()) @@ -1885,11 +1892,14 @@ impl LspInstaller for BasedPyrightLspAdapter { let path = Path::new(toolchain?.path.as_ref()) .parent()? .join(Self::BINARY_NAME); - path.exists().then(|| LanguageServerBinary { - path, - arguments: vec!["--stdio".into()], - env: None, - }) + delegate + .which(path.as_os_str()) + .await + .map(|_| LanguageServerBinary { + path, + arguments: vec!["--stdio".into()], + env: None, + }) } } @@ -1905,16 +1915,21 @@ impl LspInstaller for BasedPyrightLspAdapter { util::command::new_smol_command(pip_path.as_path()) .arg("install") .arg("basedpyright") - .arg("-U") + .arg("--upgrade") .output() - .await? + .await + .context("getting pip install output")? .status .success(), "basedpyright installation failed" ); - let pylsp = venv.join(BINARY_DIR).join(Self::BINARY_NAME); + let path = venv.join(BINARY_DIR).join(Self::BINARY_NAME); + ensure!( + delegate.which(path.as_os_str()).await.is_some(), + "basedpyright installation was incomplete" + ); Ok(LanguageServerBinary { - path: pylsp, + path, env: None, arguments: vec!["--stdio".into()], }) @@ -1926,9 +1941,10 @@ impl LspInstaller for BasedPyrightLspAdapter { delegate: &dyn LspAdapterDelegate, ) -> Option { let venv = self.base_venv(delegate).await.ok()?; - let pylsp = venv.join(BINARY_DIR).join(Self::BINARY_NAME); + let path = venv.join(BINARY_DIR).join(Self::BINARY_NAME); + delegate.which(path.as_os_str()).await?; Some(LanguageServerBinary { - path: pylsp, + path, env: None, arguments: vec!["--stdio".into()], })