Enable CSS, JSON, Python, and Tailwind to lookup LSP installed in PATH (#22037)
Co-authored-by: Peter Tripp <peter@zed.dev>
This commit is contained in:
parent
ee422dea6e
commit
7da60995cc
4 changed files with 96 additions and 25 deletions
|
@ -1,7 +1,8 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use futures::StreamExt;
|
||||
use language::{LspAdapter, LspAdapterDelegate};
|
||||
use gpui::AsyncApp;
|
||||
use language::{LanguageToolchainStore, LspAdapter, LspAdapterDelegate};
|
||||
use lsp::{LanguageServerBinary, LanguageServerName};
|
||||
use node_runtime::NodeRuntime;
|
||||
use project::Fs;
|
||||
|
@ -39,6 +40,24 @@ impl LspAdapter for CssLspAdapter {
|
|||
LanguageServerName("vscode-css-language-server".into())
|
||||
}
|
||||
|
||||
async fn check_if_user_installed(
|
||||
&self,
|
||||
delegate: &dyn LspAdapterDelegate,
|
||||
_: Arc<dyn LanguageToolchainStore>,
|
||||
_: &AsyncApp,
|
||||
) -> Option<LanguageServerBinary> {
|
||||
let path = delegate
|
||||
.which("vscode-css-language-server".as_ref())
|
||||
.await?;
|
||||
let env = delegate.shell_env().await;
|
||||
|
||||
Some(LanguageServerBinary {
|
||||
path,
|
||||
env: Some(env),
|
||||
arguments: vec!["--stdio".into()],
|
||||
})
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
_: &dyn LspAdapterDelegate,
|
||||
|
|
|
@ -149,6 +149,24 @@ impl LspAdapter for JsonLspAdapter {
|
|||
LanguageServerName("json-language-server".into())
|
||||
}
|
||||
|
||||
async fn check_if_user_installed(
|
||||
&self,
|
||||
delegate: &dyn LspAdapterDelegate,
|
||||
_: Arc<dyn LanguageToolchainStore>,
|
||||
_: &AsyncApp,
|
||||
) -> Option<LanguageServerBinary> {
|
||||
let path = delegate
|
||||
.which("vscode-json-language-server".as_ref())
|
||||
.await?;
|
||||
let env = delegate.shell_env().await;
|
||||
|
||||
Some(LanguageServerBinary {
|
||||
path,
|
||||
env: Some(env),
|
||||
arguments: vec!["--stdio".into()],
|
||||
})
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
_: &dyn LspAdapterDelegate,
|
||||
|
|
|
@ -83,19 +83,28 @@ impl LspAdapter for PythonLspAdapter {
|
|||
_: Arc<dyn LanguageToolchainStore>,
|
||||
_: &AsyncApp,
|
||||
) -> Option<LanguageServerBinary> {
|
||||
let node = delegate.which("node".as_ref()).await?;
|
||||
let (node_modules_path, _) = delegate
|
||||
.npm_package_installed_version(Self::SERVER_NAME.as_ref())
|
||||
.await
|
||||
.log_err()??;
|
||||
if let Some(pyright_bin) = delegate.which(Self::SERVER_NAME.as_ref()).await {
|
||||
let env = delegate.shell_env().await;
|
||||
Some(LanguageServerBinary {
|
||||
path: pyright_bin,
|
||||
env: Some(env),
|
||||
arguments: vec!["--stdio".into()],
|
||||
})
|
||||
} else {
|
||||
let node = delegate.which("node".as_ref()).await?;
|
||||
let (node_modules_path, _) = delegate
|
||||
.npm_package_installed_version(Self::SERVER_NAME.as_ref())
|
||||
.await
|
||||
.log_err()??;
|
||||
|
||||
let path = node_modules_path.join(NODE_MODULE_RELATIVE_SERVER_PATH);
|
||||
let path = node_modules_path.join(NODE_MODULE_RELATIVE_SERVER_PATH);
|
||||
|
||||
Some(LanguageServerBinary {
|
||||
path: node,
|
||||
env: None,
|
||||
arguments: server_binary_arguments(&path),
|
||||
})
|
||||
Some(LanguageServerBinary {
|
||||
path: node,
|
||||
env: None,
|
||||
arguments: server_binary_arguments(&path),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
|
@ -791,19 +800,28 @@ impl LspAdapter for PyLspAdapter {
|
|||
toolchains: Arc<dyn LanguageToolchainStore>,
|
||||
cx: &AsyncApp,
|
||||
) -> Option<LanguageServerBinary> {
|
||||
let venv = toolchains
|
||||
.active_toolchain(
|
||||
delegate.worktree_id(),
|
||||
LanguageName::new("Python"),
|
||||
&mut cx.clone(),
|
||||
)
|
||||
.await?;
|
||||
let pylsp_path = Path::new(venv.path.as_ref()).parent()?.join("pylsp");
|
||||
pylsp_path.exists().then(|| LanguageServerBinary {
|
||||
path: venv.path.to_string().into(),
|
||||
arguments: vec![pylsp_path.into()],
|
||||
env: None,
|
||||
})
|
||||
if let Some(pylsp_bin) = delegate.which(Self::SERVER_NAME.as_ref()).await {
|
||||
let env = delegate.shell_env().await;
|
||||
Some(LanguageServerBinary {
|
||||
path: pylsp_bin,
|
||||
env: Some(env),
|
||||
arguments: vec![],
|
||||
})
|
||||
} else {
|
||||
let venv = toolchains
|
||||
.active_toolchain(
|
||||
delegate.worktree_id(),
|
||||
LanguageName::new("Python"),
|
||||
&mut cx.clone(),
|
||||
)
|
||||
.await?;
|
||||
let pylsp_path = Path::new(venv.path.as_ref()).parent()?.join("pylsp");
|
||||
pylsp_path.exists().then(|| LanguageServerBinary {
|
||||
path: venv.path.to_string().into(),
|
||||
arguments: vec![pylsp_path.into()],
|
||||
env: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
|
|
|
@ -47,6 +47,22 @@ impl LspAdapter for TailwindLspAdapter {
|
|||
Self::SERVER_NAME.clone()
|
||||
}
|
||||
|
||||
async fn check_if_user_installed(
|
||||
&self,
|
||||
delegate: &dyn LspAdapterDelegate,
|
||||
_: Arc<dyn LanguageToolchainStore>,
|
||||
_: &AsyncApp,
|
||||
) -> Option<LanguageServerBinary> {
|
||||
let path = delegate.which(Self::SERVER_NAME.as_ref()).await?;
|
||||
let env = delegate.shell_env().await;
|
||||
|
||||
Some(LanguageServerBinary {
|
||||
path,
|
||||
env: Some(env),
|
||||
arguments: vec!["--stdio".into()],
|
||||
})
|
||||
}
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
_: &dyn LspAdapterDelegate,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue