From 3ec3ec3fda6535e8ac9da692094ba164142decfb Mon Sep 17 00:00:00 2001 From: Henry Chu Date: Sun, 15 Dec 2024 17:43:24 +0800 Subject: [PATCH] Enable css, json and tailwind to lookup LSP installed in PATH --- crates/languages/src/css.rs | 21 ++++++++++++++++++++- crates/languages/src/json.rs | 18 ++++++++++++++++++ crates/languages/src/tailwind.rs | 16 ++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/crates/languages/src/css.rs b/crates/languages/src/css.rs index 536f339664..349729de30 100644 --- a/crates/languages/src/css.rs +++ b/crates/languages/src/css.rs @@ -1,7 +1,8 @@ use anyhow::{anyhow, Result}; use async_trait::async_trait; use futures::StreamExt; -use language::{LspAdapter, LspAdapterDelegate}; +use gpui::AsyncAppContext; +use language::{LanguageToolchainStore, LspAdapter, LspAdapterDelegate}; use lsp::{LanguageServerBinary, LanguageServerName}; use node_runtime::NodeRuntime; use serde_json::json; @@ -37,6 +38,24 @@ impl LspAdapter for CssLspAdapter { LanguageServerName("vscode-css-language-server".into()) } + async fn check_if_user_installed( + &self, + delegate: &dyn LspAdapterDelegate, + _: Arc, + _: &AsyncAppContext, + ) -> Option { + 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, diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index 9c6315d2e2..cd74b60c91 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -136,6 +136,24 @@ impl LspAdapter for JsonLspAdapter { LanguageServerName("json-language-server".into()) } + async fn check_if_user_installed( + &self, + delegate: &dyn LspAdapterDelegate, + _: Arc, + _: &AsyncAppContext, + ) -> Option { + 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, diff --git a/crates/languages/src/tailwind.rs b/crates/languages/src/tailwind.rs index e2ced0f67f..72517c7398 100644 --- a/crates/languages/src/tailwind.rs +++ b/crates/languages/src/tailwind.rs @@ -46,6 +46,22 @@ impl LspAdapter for TailwindLspAdapter { Self::SERVER_NAME.clone() } + async fn check_if_user_installed( + &self, + delegate: &dyn LspAdapterDelegate, + _: Arc, + _: &AsyncAppContext, + ) -> Option { + 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,