Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

tailwind: Allow Tailwind LS to be used in Scala (#11858)

Thorsten Ball1b9014bca606
diff --git a/crates/languages/src/tailwind.rs b/crates/languages/src/tailwind.rs
index 0c17e042a01..41572257b90 100644
--- a/crates/languages/src/tailwind.rs
+++ b/crates/languages/src/tailwind.rs
@@ -6,7 +6,9 @@ use gpui::AsyncAppContext;
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
use node_runtime::NodeRuntime;
+use project::project_settings::ProjectSettings;
use serde_json::{json, Value};
+use settings::Settings;
use smol::fs;
use std::{
any::Any,
@@ -27,6 +29,8 @@ pub struct TailwindLspAdapter {
}
impl TailwindLspAdapter {
+ const SERVER_NAME: &'static str = "tailwindcss-language-server";
+
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
TailwindLspAdapter { node }
}
@@ -35,7 +39,7 @@ impl TailwindLspAdapter {
#[async_trait(?Send)]
impl LspAdapter for TailwindLspAdapter {
fn name(&self) -> LanguageServerName {
- LanguageServerName("tailwindcss-language-server".into())
+ LanguageServerName(Self::SERVER_NAME.into())
}
async fn fetch_latest_server_version(
@@ -110,11 +114,34 @@ impl LspAdapter for TailwindLspAdapter {
async fn workspace_configuration(
self: Arc<Self>,
_: &Arc<dyn LspAdapterDelegate>,
- _cx: &mut AsyncAppContext,
+ cx: &mut AsyncAppContext,
) -> Result<Value> {
+ let tailwind_user_settings = cx.update(|cx| {
+ ProjectSettings::get_global(cx)
+ .lsp
+ .get(Self::SERVER_NAME)
+ .and_then(|s| s.settings.clone())
+ .unwrap_or_default()
+ })?;
+
+ // We need to set this to null if it's not set, because tailwindcss-languageserver
+ // will check whether it's an object and if it is (even if it's empty) it will
+ // ignore the `userLanguages` from the initialization options.
+ let include_languages = tailwind_user_settings
+ .get("includeLanguages")
+ .cloned()
+ .unwrap_or(Value::Null);
+
+ let experimental = tailwind_user_settings
+ .get("experimental")
+ .cloned()
+ .unwrap_or_else(|| json!([]));
+
Ok(json!({
"tailwindCSS": {
"emmetCompletions": true,
+ "includeLanguages": include_languages,
+ "experimental": experimental,
}
}))
}