From 0130847bc0f49dabb5af91d665f584dc9b8c3e3a Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Sun, 22 Nov 2026 19:55:05 +0900 Subject: [PATCH] feat(languages): start the Tailwind CSS language server in Tailwind projects (#5199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Runs @tailwindcss/language-server next to the language's own servers for HTML, CSS, JS/JSX, TS/TSX, Vue, Svelte and Astro, only below a tailwind.config.* (v3) or a package.json listing tailwindcss in dependencies or devDependencies (v4), with one-click install like the ESLint and Angular servers. JSON root markers (package.json#…) now match a key with any non-null value, not only objects. Adds fixtures/tailwind-app and an ignored real-server test. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-language/src/lib.rs | 3 +- crates/ide-language/src/markers.rs | 26 ++++++++--- crates/ide-language/src/registry.rs | 41 ++++++++++++++++- crates/ide-lsp/tests/real_servers.rs | 67 ++++++++++++++++++++++++++++ crates/ide-tools/src/registry.rs | 12 +++++ docs/en/languages/index.mdx | 2 +- docs/en/languages/javascript.mdx | 22 ++++----- docs/zh/languages/index.mdx | 2 +- docs/zh/languages/javascript.mdx | 22 ++++----- fixtures/README.md | 1 + fixtures/tailwind-app/.gitignore | 2 + fixtures/tailwind-app/index.html | 13 ++++++ fixtures/tailwind-app/package.json | 24 ++++++++++ fixtures/tailwind-app/src/App.tsx | 15 +++++++ fixtures/tailwind-app/src/app.css | 10 +++++ fixtures/tailwind-app/src/main.tsx | 9 ++++ fixtures/tailwind-app/tsconfig.json | 12 +++++ fixtures/tailwind-app/vite.config.ts | 7 +++ languages/astro.toml | 11 +++++ languages/css.toml | 11 +++++ languages/html.toml | 11 +++++ languages/javascript.toml | 11 +++++ languages/javascriptreact.toml | 11 +++++ languages/svelte.toml | 11 +++++ languages/typescript.toml | 11 +++++ languages/typescriptreact.toml | 11 +++++ languages/vue.toml | 11 +++++ 27 files changed, 359 insertions(+), 30 deletions(-) create mode 100644 fixtures/tailwind-app/.gitignore create mode 100644 fixtures/tailwind-app/index.html create mode 100644 fixtures/tailwind-app/package.json create mode 100644 fixtures/tailwind-app/src/App.tsx create mode 100644 fixtures/tailwind-app/src/app.css create mode 100644 fixtures/tailwind-app/src/main.tsx create mode 100644 fixtures/tailwind-app/tsconfig.json create mode 100644 fixtures/tailwind-app/vite.config.ts diff --git a/crates/ide-language/src/lib.rs b/crates/ide-language/src/lib.rs index 4cf4af1f7..1d41b6a6f 100644 --- a/crates/ide-language/src/lib.rs +++ b/crates/ide-language/src/lib.rs @@ -156,7 +156,8 @@ pub struct LanguageServerConfig { pub requires_env: Vec, /// Files whose presence marks a workspace root, e.g. `Cargo.toml`; /// `file#table` requires the TOML file to contain that dotted table, e.g. - /// `pyproject.toml#tool.ruff`. + /// `pyproject.toml#tool.ruff`, or the JSON file that dotted key, e.g. + /// `package.json#devDependencies.tailwindcss`. #[serde(default)] pub root_markers: Vec, /// Serve only files below a root marker, not the whole project: a framework's diff --git a/crates/ide-language/src/markers.rs b/crates/ide-language/src/markers.rs index d78ae08ec..752f941a7 100644 --- a/crates/ide-language/src/markers.rs +++ b/crates/ide-language/src/markers.rs @@ -58,11 +58,12 @@ pub fn arduino_sketch_root(project: &Path, path: &Path) -> Option { /// `dir` contains `marker`: a relative path, a file name pattern with one /// `*` (`*.csproj`), or a TOML or JSON file name (no pattern) and a dotted table -/// it must contain (`pyproject.toml#tool.ruff`, `package.json#eslintConfig`). +/// or JSON key it must contain (`pyproject.toml#tool.ruff`, `package.json#eslintConfig`, +/// `package.json#devDependencies.tailwindcss`). fn has_marker(dir: &Path, marker: &str) -> bool { if let Some((file, table)) = marker.split_once('#') { return if file.ends_with(".json") { - has_json_object(&dir.join(file), table) + has_json_key(&dir.join(file), table) } else { has_toml_table(&dir.join(file), table) }; @@ -88,11 +89,12 @@ fn has_toml_table(file: &Path, table: &str) -> bool { table.split('.').try_fold(&value, |v, key| v.get(key)).is_some_and(toml::Value::is_table) } -/// `file` parses as JSON and has the dotted object `key` (`eslintConfig`). -fn has_json_object(file: &Path, key: &str) -> bool { +/// `file` parses as JSON and has the dotted `key` with a value other than `null`: +/// an object (`eslintConfig`) or a dependency's version (`dependencies.tailwindcss`). +fn has_json_key(file: &Path, key: &str) -> bool { let Ok(text) = std::fs::read_to_string(file) else { return false }; let Ok(value) = serde_json::from_str::(&text) else { return false }; - key.split('.').try_fold(&value, |v, key| v.get(key)).is_some_and(serde_json::Value::is_object) + key.split('.').try_fold(&value, |v, key| v.get(key)).is_some_and(|v| !v.is_null()) } /// `path` is (or, after its creation or removal, was) a root marker of the @@ -177,6 +179,20 @@ mod tests { assert!(!is_marker_path(&root.join("svc/setup.cfg"), "pyproject.toml#tool.ruff")); } + #[test] + fn json_markers_need_their_key() { + let tmp = tempfile::tempdir().unwrap(); + let dir = tmp.path(); + let marker = "package.json#devDependencies.tailwindcss"; + std::fs::write(dir.join("package.json"), r#"{"devDependencies": {"vite": "^7.0.0"}}"#).unwrap(); + assert!(!has_marker(dir, marker)); + std::fs::write(dir.join("package.json"), r#"{"devDependencies": {"tailwindcss": "^4.1.0"}}"#).unwrap(); + assert!(has_marker(dir, marker) && !has_marker(dir, "package.json#dependencies.tailwindcss")); + std::fs::write(dir.join("package.json"), r#"{"eslintConfig": null}"#).unwrap(); + assert!(!has_marker(dir, "package.json#eslintConfig")); + assert!(is_marker_path(&dir.join("package.json"), marker)); + } + #[test] fn patterns_match_file_names() { let tmp = tempfile::tempdir().unwrap(); diff --git a/crates/ide-language/src/registry.rs b/crates/ide-language/src/registry.rs index c4e556b44..728f504f3 100644 --- a/crates/ide-language/src/registry.rs +++ b/crates/ide-language/src/registry.rs @@ -715,9 +715,19 @@ mod tests { // it); before the HTML server (hover, rename and symbols take the first). assert_eq!( names("typescript"), - ["vtsls", "typescript-language-server", "angular-language-server", "oxlint", "eslint"] + [ + "vtsls", + "typescript-language-server", + "angular-language-server", + "oxlint", + "eslint", + "tailwindcss-language-server" + ] + ); + assert_eq!( + names("html"), + ["angular-language-server", "vscode-html-language-server", "tailwindcss-language-server"] ); - assert_eq!(names("html"), ["angular-language-server", "vscode-html-language-server"]); for lang in ["typescript", "html"] { let cfg = reg.get(&LanguageId::new(lang)).unwrap(); let angular = cfg.language_servers.iter().find(|s| s.name == "angular-language-server").unwrap(); @@ -771,6 +781,33 @@ mod tests { } } + #[test] + fn tailwind_serves_web_files_only_in_tailwind_projects() { + let reg = reg(); + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + for dir in ["v3/src", "v4/src", "plain/src"] { + std::fs::create_dir_all(root.join(dir)).unwrap(); + } + std::fs::write(root.join("v3/tailwind.config.js"), "module.exports = {};").unwrap(); + std::fs::write(root.join("v4/package.json"), r#"{"devDependencies": {"tailwindcss": "^4.1.0"}}"#).unwrap(); + std::fs::write(root.join("plain/package.json"), r#"{"devDependencies": {"vite": "^7.0.0"}}"#).unwrap(); + for lang in + ["html", "css", "javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "svelte", "astro"] + { + let cfg = reg.get(&LanguageId::new(lang)).unwrap(); + // Last: the language's own servers answer hover first. + let tailwind = cfg.language_servers.last().unwrap(); + assert_eq!(tailwind.name, "tailwindcss-language-server", "{lang}"); + assert_eq!(tailwind.args, ["--stdio"], "{lang}"); + assert!(tailwind.require_root_marker && !tailwind.fallback, "{lang}"); + let served = |file: &str| crate::marked_root(Some(root), &root.join(file), &tailwind.root_markers); + assert_eq!(served("v3/src/app.css"), Some(root.join("v3")), "{lang}"); + assert_eq!(served("v4/src/app.css"), Some(root.join("v4")), "{lang}"); + assert_eq!(served("plain/src/app.css"), None, "{lang}: package.json without tailwindcss"); + } + } + #[test] fn laravel_lsp_serves_php_files_only_below_artisan() { let reg = reg(); diff --git a/crates/ide-lsp/tests/real_servers.rs b/crates/ide-lsp/tests/real_servers.rs index c12e476fb..0a52a5d16 100644 --- a/crates/ide-lsp/tests/real_servers.rs +++ b/crates/ide-lsp/tests/real_servers.rs @@ -947,6 +947,73 @@ async fn angular_language_server_end_to_end() { tokio::time::timeout(Duration::from_secs(10), mgr.shutdown_all()).await.unwrap(); } +/// The Tailwind CSS server on `fixtures/tailwind-app` (Tailwind 4, `@theme` colours), with +/// the built-in definitions: class completion in JSX and `@apply`, hover with the generated +/// CSS, and the class conflict warning. Set `OPENIDEA_TEST_NPM_TOOLS` to a dir with +/// `npm i @tailwindcss/language-server`; the fixture's own `tailwindcss` isn't needed. +#[tokio::test(flavor = "multi_thread")] +#[ignore = "requires @tailwindcss/language-server (OPENIDEA_TEST_NPM_TOOLS)"] +async fn tailwindcss_language_server_end_to_end() { + let tools = std::path::PathBuf::from(std::env::var("OPENIDEA_TEST_NPM_TOOLS").expect("OPENIDEA_TEST_NPM_TOOLS")); + let dir = tempfile::tempdir().unwrap(); + let root = dir.path().canonicalize().unwrap(); + let fixture = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/tailwind-app"); + for file in ["package.json", "index.html", "src/app.css", "src/App.tsx"] { + std::fs::create_dir_all(root.join(file).parent().unwrap()).unwrap(); + std::fs::copy(fixture.join(file), root.join(file)).unwrap(); + } + let builtin = LanguageRegistry::load(None).unwrap(); + let languages = ["typescriptreact", "css"].map(|id| { + let mut cfg = builtin.get(&LanguageId::new(id)).unwrap(); + cfg.language_servers.retain(|s| s.name == "tailwindcss-language-server"); + let bin = tools.join("node_modules/.bin/tailwindcss-language-server"); + cfg.language_servers[0].command = bin.to_string_lossy().into_owned(); + cfg + }); + let (mgr, events) = manager(&root, LanguageRegistry::from_configs(languages.to_vec())); + let (tsx, css) = (DocId::next(), DocId::next()); + let tsx_path = root.join("src/App.tsx"); + let css_path = root.join("src/app.css"); + let tsx_text = std::fs::read_to_string(&tsx_path).unwrap(); + let css_text = std::fs::read_to_string(&css_path).unwrap(); + mgr.did_open(tsx, &tsx_path, &LanguageId::new("typescriptreact"), 1, &tsx_text); + mgr.did_open(css, &css_path, &LanguageId::new("css"), 1, &css_text); + let at = |text: &str, needle: &str, offset: usize| { + let (line, l) = text.lines().enumerate().find(|(_, l)| l.contains(needle)).unwrap(); + Pos::new(line as u32, (l.find(needle).unwrap() + offset) as u32) + }; + + // The project's own `@theme` colour, in `className` and after `@apply`. + let in_class = at(&tsx_text, "className=\"flex flex-col", "className=\"".len()); + let in_apply = at(&css_text, "@apply rounded-md", "@apply ".len()); + for (doc, pos) in [(tsx, in_class), (css, in_apply)] { + retry("class completion", Duration::from_secs(60), || { + let mgr = mgr.clone(); + async move { + let list = mgr.completion(doc, pos, None, Default::default()).await.ok()?; + list.items.iter().any(|i| i.label == "bg-brand-500").then_some(()) + } + }) + .await; + } + let hover = mgr.hover(tsx, at(&tsx_text, "bg-white", 1), Default::default()).await.unwrap().unwrap(); + assert!(hover.contents.value.contains("background-color"), "{}", hover.contents.value); + let hover = mgr.hover(tsx, at(&tsx_text, "text-brand-700", 1), Default::default()).await.unwrap().unwrap(); + assert!(hover.contents.value.contains("--color-brand-700"), "{}", hover.contents.value); + + // `flex block`: both set `display`. + retry("class conflict", Duration::from_secs(30), || { + let found = events.lock().iter().any(|e| { + matches!(e, IdeEvent::Diagnostics { path, items, .. } + if path.ends_with("src/App.tsx") + && items.iter().any(|d| d.message.contains("applies the same CSS properties"))) + }); + async move { found.then_some(()) } + }) + .await; + tokio::time::timeout(Duration::from_secs(10), mgr.shutdown_all()).await.unwrap(); +} + /// A notebook's code cells on basedpyright and Ruff (LSP 3.17 notebook sync): names flow from /// earlier cells, IPython magics parse, and locations and diagnostics name the cells. #[tokio::test(flavor = "multi_thread")] diff --git a/crates/ide-tools/src/registry.rs b/crates/ide-tools/src/registry.rs index e4c1deb29..6456db336 100644 --- a/crates/ide-tools/src/registry.rs +++ b/crates/ide-tools/src/registry.rs @@ -444,6 +444,18 @@ pub static TOOLS: &[ToolSpec] = &[ homepage: "https://angular.dev/tools/language-service", needs: &[], }, + ToolSpec { + name: "tailwindcss-language-server", + display: "Tailwind CSS Language Server", + kind: LanguageServer, + commands: &["tailwindcss-language-server"], + // Brings Tailwind CSS 3 and 4 for projects whose own `tailwindcss` isn't installed yet. + method: Method::Npm { packages: &["@tailwindcss/language-server"] }, + fallback: None, + version: V, + homepage: "https://github.com/tailwindlabs/tailwindcss-intellisense", + needs: NODE, + }, ToolSpec { name: "graphql-lsp", display: "GraphQL Language Server", diff --git a/docs/en/languages/index.mdx b/docs/en/languages/index.mdx index 92b88990e..ec13ac0cf 100644 --- a/docs/en/languages/index.mdx +++ b/docs/en/languages/index.mdx @@ -34,7 +34,7 @@ For a recognized file, support comes in layers: A language can list more than one server: - **Alternatives** (shown as `a → b` in the table below): only the first one that is installed runs. Python, for example, uses basedpyright, and falls back to pyright, ty or pyrefly only when basedpyright is missing. In **Settings › Languages & Frameworks › Language Servers** you can pick one of them or set the choice to **Automatic** (the first one available). -- **Additions** (shown as `+ b`): run next to the main server, usually only in projects that use them. Ruff joins basedpyright in projects with a Ruff configuration; oxlint joins vtsls in projects with an oxlint configuration; the Angular and Laravel servers join in Angular and Laravel projects. +- **Additions** (shown as `+ b`): run next to the main server, usually only in projects that use them. Ruff joins basedpyright in projects with a Ruff configuration; oxlint joins vtsls in projects with an oxlint configuration; the Angular, Laravel and Tailwind CSS servers join in Angular, Laravel and Tailwind CSS projects. ## Installing language servers and debuggers diff --git a/docs/en/languages/javascript.mdx b/docs/en/languages/javascript.mdx index b6f2e685b..d34abfc0d 100644 --- a/docs/en/languages/javascript.mdx +++ b/docs/en/languages/javascript.mdx @@ -7,16 +7,17 @@ OpenIDEA edits JavaScript (`.js`, `.mjs`, `.cjs`, `.jsx`) and TypeScript (`.ts`, ## Language servers -| Files | Server | Notes | -| ------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -| JS, JSX, TS, TSX | `vtsls` | Default TypeScript server. | -| JS, JSX, TS, TSX | `typescript-language-server` | Fallback: used only while `vtsls` is not installed. | -| `.vue` | `vue-language-server` + `vtsls` | Vue's hybrid mode: TypeScript inside `.vue` files comes from `vtsls` with `@vue/typescript-plugin`. | -| `.svelte` | `svelte-language-server` | | -| `.astro` | `astro-ls` | Needs Node.js and a TypeScript library. | -| TS and HTML in Angular projects | `angular-language-server` (`ngserver`) | Only below `angular.json` or `node_modules/@angular/core`. | -| All of the above | `oxlint` | Only below an `.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts` or `oxlint.config.mts`. | -| All of the above | `vscode-eslint-language-server` (ESLint) | Only below an ESLint configuration (`eslint.config.*`, `.eslintrc*` or `eslintConfig` in `package.json`); runs the project's own `eslint`. | +| Files | Server | Notes | +| ------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| JS, JSX, TS, TSX | `vtsls` | Default TypeScript server. | +| JS, JSX, TS, TSX | `typescript-language-server` | Fallback: used only while `vtsls` is not installed. | +| `.vue` | `vue-language-server` + `vtsls` | Vue's hybrid mode: TypeScript inside `.vue` files comes from `vtsls` with `@vue/typescript-plugin`. | +| `.svelte` | `svelte-language-server` | | +| `.astro` | `astro-ls` | Needs Node.js and a TypeScript library. | +| TS and HTML in Angular projects | `angular-language-server` (`ngserver`) | Only below `angular.json` or `node_modules/@angular/core`. | +| All of the above | `oxlint` | Only below an `.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts` or `oxlint.config.mts`. | +| All of the above | `vscode-eslint-language-server` (ESLint) | Only below an ESLint configuration (`eslint.config.*`, `.eslintrc*` or `eslintConfig` in `package.json`); runs the project's own `eslint`. | +| All of the above, HTML and CSS | `tailwindcss-language-server` (Tailwind CSS) | Only below a `tailwind.config.*` or a `package.json` that depends on `tailwindcss`: class completion, hover with the generated CSS, and class diagnostics. | The TypeScript servers start for a workspace marked by `tsconfig.json`, `jsconfig.json` or `package.json`. Files outside any `tsconfig.json` / `jsconfig.json` are still registered with tsserver, so loose scripts get code insight too. @@ -47,6 +48,7 @@ All servers, debuggers and formatters are listed in **Settings › Languages & F | `vtsls`, `typescript-language-server` | npm (`@vtsls/language-server`; `typescript-language-server` + `typescript@6`) | | `vue-language-server`, `svelte-language-server`, `astro-ls`, `angular-language-server` | npm | | `oxlint` | npm | +| `tailwindcss-language-server` | npm (`@tailwindcss/language-server`) | | Prettier, oxfmt | npm | | JavaScript Debugger (vscode-js-debug) | GitHub release (`microsoft/vscode-js-debug`) | diff --git a/docs/zh/languages/index.mdx b/docs/zh/languages/index.mdx index 5aff7d56c..ed6e661e9 100644 --- a/docs/zh/languages/index.mdx +++ b/docs/zh/languages/index.mdx @@ -32,7 +32,7 @@ OpenIDEA 用一个小的定义文件 `languages/.toml` 描述每种语言: 一种语言可以配置多个服务器: - **备选**(下表中写作 `a → b`):只运行第一个已安装的。例如 Python 默认用 basedpyright,只有它缺失时才退回 pyright、ty 或 pyrefly。在 **设置 › 语言和框架 › 语言服务器** 中可以指定其中一个,或选 **自动**(使用第一个可用的)。 -- **附加**(写作 `+ b`):和主服务器同时运行,通常只在用到它的项目中启用。带 Ruff 配置的项目里 Ruff 与 basedpyright 一起运行;带 oxlint 配置的项目里 oxlint 与 vtsls 一起运行;Angular 和 Laravel 项目里分别加上 Angular 和 Laravel 的服务器。 +- **附加**(写作 `+ b`):和主服务器同时运行,通常只在用到它的项目中启用。带 Ruff 配置的项目里 Ruff 与 basedpyright 一起运行;带 oxlint 配置的项目里 oxlint 与 vtsls 一起运行;Angular、Laravel 和 Tailwind CSS 项目里分别加上 Angular、Laravel 和 Tailwind CSS 的服务器。 ## 安装语言服务器和调试器 diff --git a/docs/zh/languages/javascript.mdx b/docs/zh/languages/javascript.mdx index 5a298fcb7..2c17247df 100644 --- a/docs/zh/languages/javascript.mdx +++ b/docs/zh/languages/javascript.mdx @@ -7,16 +7,17 @@ OpenIDEA 打开 JavaScript(`.js`、`.mjs`、`.cjs`、`.jsx`)和 TypeScript ## 语言服务器 -| 文件 | 服务器 | 说明 | -| --------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -| JS、JSX、TS、TSX | `vtsls` | 默认的 TypeScript 服务器。 | -| JS、JSX、TS、TSX | `typescript-language-server` | 备选:仅在未安装 `vtsls` 时使用。 | -| `.vue` | `vue-language-server` + `vtsls` | Vue 的 hybrid 模式:`.vue` 中的 TypeScript 由加载了 `@vue/typescript-plugin` 的 `vtsls` 处理。 | -| `.svelte` | `svelte-language-server` | | -| `.astro` | `astro-ls` | 需要 Node.js 和 TypeScript 库。 | -| Angular 项目中的 TS 和 HTML | `angular-language-server`(`ngserver`) | 只在 `angular.json` 或 `node_modules/@angular/core` 所在目录之下启用。 | -| 以上全部 | `oxlint` | 只在存在 `.oxlintrc.json`、`.oxlintrc.jsonc`、`oxlint.config.ts` 或 `oxlint.config.mts` 的目录之下启用。 | -| 以上全部 | `vscode-eslint-language-server`(ESLint) | 只在 ESLint 配置(`eslint.config.*`、`.eslintrc*` 或 `package.json` 中的 `eslintConfig`)所在目录之下启用,运行项目自己的 `eslint`。 | +| 文件 | 服务器 | 说明 | +| --------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| JS、JSX、TS、TSX | `vtsls` | 默认的 TypeScript 服务器。 | +| JS、JSX、TS、TSX | `typescript-language-server` | 备选:仅在未安装 `vtsls` 时使用。 | +| `.vue` | `vue-language-server` + `vtsls` | Vue 的 hybrid 模式:`.vue` 中的 TypeScript 由加载了 `@vue/typescript-plugin` 的 `vtsls` 处理。 | +| `.svelte` | `svelte-language-server` | | +| `.astro` | `astro-ls` | 需要 Node.js 和 TypeScript 库。 | +| Angular 项目中的 TS 和 HTML | `angular-language-server`(`ngserver`) | 只在 `angular.json` 或 `node_modules/@angular/core` 所在目录之下启用。 | +| 以上全部 | `oxlint` | 只在存在 `.oxlintrc.json`、`.oxlintrc.jsonc`、`oxlint.config.ts` 或 `oxlint.config.mts` 的目录之下启用。 | +| 以上全部 | `vscode-eslint-language-server`(ESLint) | 只在 ESLint 配置(`eslint.config.*`、`.eslintrc*` 或 `package.json` 中的 `eslintConfig`)所在目录之下启用,运行项目自己的 `eslint`。 | +| 以上全部及 HTML、CSS | `tailwindcss-language-server`(Tailwind CSS) | 只在 `tailwind.config.*` 或依赖了 `tailwindcss` 的 `package.json` 所在目录之下启用:类名补全、悬停显示生成的 CSS、类名诊断。 | TypeScript 服务器以 `tsconfig.json`、`jsconfig.json` 或 `package.json` 所在目录为工作区根。不属于任何 `tsconfig.json` / `jsconfig.json` 的文件也会注册给 tsserver,零散脚本同样有代码智能。 @@ -47,6 +48,7 @@ Vue、Astro 和 Angular 服务器也会使用这里选择的版本。TypeScript | `vtsls`、`typescript-language-server` | npm(`@vtsls/language-server`;`typescript-language-server` + `typescript@6`) | | `vue-language-server`、`svelte-language-server`、`astro-ls`、`angular-language-server` | npm | | `oxlint` | npm | +| `tailwindcss-language-server` | npm(`@tailwindcss/language-server`) | | Prettier、oxfmt | npm | | JavaScript 调试器(vscode-js-debug) | GitHub release(`microsoft/vscode-js-debug`) | diff --git a/fixtures/README.md b/fixtures/README.md index 610c30b15..cfb2627a9 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -19,6 +19,7 @@ something to show. | `c-app/` | gcc / g++ 12+, make, GDB 14+ | `make all` | — | — | — | | `php-app/` | PHP 8.5, Composer | `composer quote` | `vendor/bin/pest` | `OPENIDEA_FAIL=1 vendor/bin/pest` | unused variable in `ThresholdCustoms.php` | | `django-app/` | Python 3.10+, Django 5.2+ | `python manage.py runserver` | `python manage.py test` | `OPENIDEA_FAIL=1 python manage.py test` | unused import in `shop/views.py` | +| `tailwind-app/` | Node 22+, pnpm/npm, Tailwind CSS 4, React | `pnpm dev` | — | — | `flex` conflicting with `block` in `src/App.tsx` | | `zig-app/` | Zig 0.17 | `zig build run` | `zig build test` | — | — | | `polyglot/` | Go, TS, Python, C, shell, SQL, TOML/YAML/JSON, proto, Terraform | `make` | `make test` | — | unused variable in `native/hash.c` | diff --git a/fixtures/tailwind-app/.gitignore b/fixtures/tailwind-app/.gitignore new file mode 100644 index 000000000..f06235c46 --- /dev/null +++ b/fixtures/tailwind-app/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/fixtures/tailwind-app/index.html b/fixtures/tailwind-app/index.html new file mode 100644 index 000000000..111c5054d --- /dev/null +++ b/fixtures/tailwind-app/index.html @@ -0,0 +1,13 @@ + + + + + + Tailwind fixture + + + +
+ + + diff --git a/fixtures/tailwind-app/package.json b/fixtures/tailwind-app/package.json new file mode 100644 index 000000000..c25b26109 --- /dev/null +++ b/fixtures/tailwind-app/package.json @@ -0,0 +1,24 @@ +{ + "name": "openidea-fixture-tailwind", + "version": "0.1.0", + "private": true, + "description": "OpenIDEA QA fixture: a Tailwind CSS 4 page with React", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc -p . && vite build" + }, + "dependencies": { + "react": "^19.0.0", + "react-dom": "^19.0.0" + }, + "devDependencies": { + "@tailwindcss/vite": "^4.1.0", + "@types/react": "^19.0.0", + "@types/react-dom": "^19.0.0", + "@vitejs/plugin-react": "^5.0.0", + "tailwindcss": "^4.1.0", + "typescript": "^5.6.0", + "vite": "^7.0.0" + } +} diff --git a/fixtures/tailwind-app/src/App.tsx b/fixtures/tailwind-app/src/App.tsx new file mode 100644 index 000000000..e79262b6d --- /dev/null +++ b/fixtures/tailwind-app/src/App.tsx @@ -0,0 +1,15 @@ +import { useState } from "react"; + +export function App() { + const [count, setCount] = useState(0); + return ( +
+

Tailwind CSS fixture

+ {/* Intentional warning: `flex` and `block` both set `display`. */} +

Clicked {count} times.

+ +
+ ); +} diff --git a/fixtures/tailwind-app/src/app.css b/fixtures/tailwind-app/src/app.css new file mode 100644 index 000000000..f51467238 --- /dev/null +++ b/fixtures/tailwind-app/src/app.css @@ -0,0 +1,10 @@ +@import "tailwindcss"; + +@theme { + --color-brand-500: oklch(0.62 0.19 259); + --color-brand-700: oklch(0.49 0.17 262); +} + +.btn { + @apply rounded-md bg-brand-500 px-4 py-2 font-medium text-white hover:bg-brand-700; +} diff --git a/fixtures/tailwind-app/src/main.tsx b/fixtures/tailwind-app/src/main.tsx new file mode 100644 index 000000000..1c711a7b4 --- /dev/null +++ b/fixtures/tailwind-app/src/main.tsx @@ -0,0 +1,9 @@ +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; +import { App } from "./App"; + +createRoot(document.getElementById("root")!).render( + + + , +); diff --git a/fixtures/tailwind-app/tsconfig.json b/fixtures/tailwind-app/tsconfig.json new file mode 100644 index 000000000..f7216161d --- /dev/null +++ b/fixtures/tailwind-app/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "bundler", + "jsx": "react-jsx", + "strict": true, + "noEmit": true, + "skipLibCheck": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/fixtures/tailwind-app/vite.config.ts b/fixtures/tailwind-app/vite.config.ts new file mode 100644 index 000000000..fcdeea237 --- /dev/null +++ b/fixtures/tailwind-app/vite.config.ts @@ -0,0 +1,7 @@ +import tailwindcss from "@tailwindcss/vite"; +import react from "@vitejs/plugin-react"; +import { defineConfig } from "vite"; + +export default defineConfig({ + plugins: [react(), tailwindcss()], +}); diff --git a/languages/astro.toml b/languages/astro.toml index 5f7411544..546b166c0 100644 --- a/languages/astro.toml +++ b/languages/astro.toml @@ -45,6 +45,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + # Components run in the browser: breakpoints in them are hit by a JavaScript Debug configuration. [debugger] adapter = "js-debug" diff --git a/languages/css.toml b/languages/css.toml index 4f8ba1e11..4c81bbde6 100644 --- a/languages/css.toml +++ b/languages/css.toml @@ -13,3 +13,14 @@ command = "vscode-css-language-server" args = ["--stdio"] initialization-options = { provideFormatter = true, css = {}, scss = {}, less = {} } install-hint = "npm i -g vscode-langservers-extracted" + +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" diff --git a/languages/html.toml b/languages/html.toml index 1b62c4238..7d9492754 100644 --- a/languages/html.toml +++ b/languages/html.toml @@ -41,6 +41,17 @@ args = ["--stdio"] initialization-options = { provideFormatter = true, embeddedLanguages = { css = true, javascript = true } } install-hint = "npm i -g vscode-langservers-extracted" +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + # Scripts in a page run in the browser: breakpoints in them are hit by a JavaScript Debug configuration. [debugger] adapter = "js-debug" diff --git a/languages/javascript.toml b/languages/javascript.toml index e4b14ce0f..a8b95c397 100644 --- a/languages/javascript.toml +++ b/languages/javascript.toml @@ -106,6 +106,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + [debugger] adapter = "js-debug" command = "js-debug-adapter" diff --git a/languages/javascriptreact.toml b/languages/javascriptreact.toml index 79dc30323..b744b8139 100644 --- a/languages/javascriptreact.toml +++ b/languages/javascriptreact.toml @@ -109,6 +109,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + [debugger] adapter = "js-debug" command = "js-debug-adapter" diff --git a/languages/svelte.toml b/languages/svelte.toml index 7e5741448..d402a9d7f 100644 --- a/languages/svelte.toml +++ b/languages/svelte.toml @@ -51,6 +51,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + # Components run in the browser: breakpoints in them are hit by a JavaScript Debug configuration. [debugger] adapter = "js-debug" diff --git a/languages/typescript.toml b/languages/typescript.toml index 95d93a7b8..08f65b3a1 100644 --- a/languages/typescript.toml +++ b/languages/typescript.toml @@ -124,6 +124,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + [debugger] adapter = "js-debug" command = "js-debug-adapter" diff --git a/languages/typescriptreact.toml b/languages/typescriptreact.toml index 66dd64330..33b67c090 100644 --- a/languages/typescriptreact.toml +++ b/languages/typescriptreact.toml @@ -110,6 +110,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + [debugger] adapter = "js-debug" command = "js-debug-adapter" diff --git a/languages/vue.toml b/languages/vue.toml index 7d54c4365..77b9e58a2 100644 --- a/languages/vue.toml +++ b/languages/vue.toml @@ -88,6 +88,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind +# (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, +# which answer hover first. +[[language-servers]] +name = "tailwindcss-language-server" +command = "tailwindcss-language-server" +args = ["--stdio"] +root-markers = ["tailwind.config.*", "package.json#dependencies.tailwindcss", "package.json#devDependencies.tailwindcss"] +require-root-marker = true +install-hint = "npm i -g @tailwindcss/language-server" + # Components run in the browser: breakpoints in them are hit by a JavaScript Debug configuration. [debugger] adapter = "js-debug"