pylsp: Prefer version from user venv (#21069)

Closes #ISSUE

Release Notes:

- pylsp will now use version installed in user venv, if one is
available.
This commit is contained in:
Piotr Osiewicz 2024-11-25 00:54:47 +01:00 committed by GitHub
parent 20bffaf93f
commit e85848a695
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 37 additions and 23 deletions

View file

@ -201,13 +201,14 @@ impl CachedLspAdapter {
pub async fn get_language_server_command(
self: Arc<Self>,
delegate: Arc<dyn LspAdapterDelegate>,
toolchains: Arc<dyn LanguageToolchainStore>,
binary_options: LanguageServerBinaryOptions,
cx: &mut AsyncAppContext,
) -> Result<LanguageServerBinary> {
let cached_binary = self.cached_binary.lock().await;
self.adapter
.clone()
.get_language_server_command(delegate, binary_options, cached_binary, cx)
.get_language_server_command(delegate, toolchains, binary_options, cached_binary, cx)
.await
}
@ -281,6 +282,7 @@ pub trait LspAdapter: 'static + Send + Sync {
fn get_language_server_command<'a>(
self: Arc<Self>,
delegate: Arc<dyn LspAdapterDelegate>,
toolchains: Arc<dyn LanguageToolchainStore>,
binary_options: LanguageServerBinaryOptions,
mut cached_binary: futures::lock::MutexGuard<'a, Option<LanguageServerBinary>>,
cx: &'a mut AsyncAppContext,
@ -298,7 +300,7 @@ pub trait LspAdapter: 'static + Send + Sync {
// because we don't want to download and overwrite our global one
// for each worktree we might have open.
if binary_options.allow_path_lookup {
if let Some(binary) = self.check_if_user_installed(delegate.as_ref(), cx).await {
if let Some(binary) = self.check_if_user_installed(delegate.as_ref(), toolchains, cx).await {
log::info!(
"found user-installed language server for {}. path: {:?}, arguments: {:?}",
self.name().0,
@ -357,6 +359,7 @@ pub trait LspAdapter: 'static + Send + Sync {
async fn check_if_user_installed(
&self,
_: &dyn LspAdapterDelegate,
_: Arc<dyn LanguageToolchainStore>,
_: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
None
@ -1665,6 +1668,7 @@ impl LspAdapter for FakeLspAdapter {
async fn check_if_user_installed(
&self,
_: &dyn LspAdapterDelegate,
_: Arc<dyn LanguageToolchainStore>,
_: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
Some(self.language_server_binary.clone())
@ -1673,6 +1677,7 @@ impl LspAdapter for FakeLspAdapter {
fn get_language_server_command<'a>(
self: Arc<Self>,
_: Arc<dyn LspAdapterDelegate>,
_: Arc<dyn LanguageToolchainStore>,
_: LanguageServerBinaryOptions,
_: futures::lock::MutexGuard<'a, Option<LanguageServerBinary>>,
_: &'a mut AsyncAppContext,