Add pyright workspace configuration (#14265)

Release Notes:

- Added support for pyright workspace configuration, as described in
https://microsoft.github.io/pyright/#/settings .
This commit is contained in:
FilipeBisinella 2024-07-12 19:13:09 -03:00 committed by GitHub
parent 3deb000f70
commit 21c5ce2bbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 72 additions and 3 deletions

View file

@ -1,9 +1,13 @@
use anyhow::Result;
use async_trait::async_trait;
use gpui::AppContext;
use gpui::AsyncAppContext;
use language::{ContextProvider, LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
use node_runtime::NodeRuntime;
use project::project_settings::ProjectSettings;
use serde_json::Value;
use settings::Settings;
use std::{
any::Any,
borrow::Cow,
@ -25,6 +29,8 @@ pub struct PythonLspAdapter {
}
impl PythonLspAdapter {
const SERVER_NAME: &'static str = "pyright";
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
PythonLspAdapter { node }
}
@ -33,14 +39,18 @@ impl PythonLspAdapter {
#[async_trait(?Send)]
impl LspAdapter for PythonLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName("pyright".into())
LanguageServerName(Self::SERVER_NAME.into())
}
async fn fetch_latest_server_version(
&self,
_: &dyn LspAdapterDelegate,
) -> Result<Box<dyn 'static + Any + Send>> {
Ok(Box::new(self.node.npm_package_latest_version("pyright").await?) as Box<_>)
Ok(Box::new(
self.node
.npm_package_latest_version(Self::SERVER_NAME)
.await?,
) as Box<_>)
}
async fn fetch_server_binary(
@ -51,7 +61,7 @@ impl LspAdapter for PythonLspAdapter {
) -> Result<LanguageServerBinary> {
let latest_version = latest_version.downcast::<String>().unwrap();
let server_path = container_dir.join(SERVER_PATH);
let package_name = "pyright";
let package_name = Self::SERVER_NAME;
let should_install_language_server = self
.node
@ -164,6 +174,20 @@ impl LspAdapter for PythonLspAdapter {
filter_range,
})
}
async fn workspace_configuration(
self: Arc<Self>,
_: &Arc<dyn LspAdapterDelegate>,
cx: &mut AsyncAppContext,
) -> Result<Value> {
cx.update(|cx| {
ProjectSettings::get_global(cx)
.lsp
.get(Self::SERVER_NAME)
.and_then(|s| s.settings.clone())
.unwrap_or_default()
})
}
}
async fn get_cached_server_binary(