From b787df7ce0279fd7a1c4f3a772af553ee6cd9fd9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 18 Feb 2025 07:40:04 -0500 Subject: [PATCH 1/4] Add failing test --- .../src/project-locator.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/tailwindcss-language-server/src/project-locator.test.ts b/packages/tailwindcss-language-server/src/project-locator.test.ts index 7071b65f0..e2b23de71 100644 --- a/packages/tailwindcss-language-server/src/project-locator.test.ts +++ b/packages/tailwindcss-language-server/src/project-locator.test.ts @@ -279,6 +279,48 @@ testLocator({ ], }) +testLocator({ + name: 'Roots are detected when they indirectly use Tailwind features', + fs: { + 'package.json': json` + { + "dependencies": { + "tailwindcss": "4.0.6" + } + } + `, + // TODO: This is marked as the root which is… maybe fine but not sure + // The intention in this example is that src/globals.css is the real root + // but if src/articles.css suddenly gained `@theme` blocks then maybe it'd + // need to be the root instead. + 'src/articles/articles.css': css` + @reference "../globals.css"; + .article-title { + @apply text-primary; + } + `, + 'src/articles/layout.js': js` + import "./articles.css"; + export default function Layout(children) { + return children; + } + `, + 'src/globals.css': scss` + @import "tailwindcss"; + @theme { + --color-primary: #3490dc; + } + `, + }, + expected: [ + { + version: '4.0.6', + config: '/src/articles/articles.css', + content: [], + }, + ], +}) + // --- function testLocator({ From c8eaa7bf50811b210e6366cecfb4a7f2d70b2fe2 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 18 Feb 2025 07:39:13 -0500 Subject: [PATCH 2/4] Tweak test options --- .../tailwindcss-language-server/src/project-locator.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss-language-server/src/project-locator.test.ts b/packages/tailwindcss-language-server/src/project-locator.test.ts index e2b23de71..6414a099c 100644 --- a/packages/tailwindcss-language-server/src/project-locator.test.ts +++ b/packages/tailwindcss-language-server/src/project-locator.test.ts @@ -1,4 +1,4 @@ -import { expect, test } from 'vitest' +import { expect, test, TestOptions } from 'vitest' import * as path from 'node:path' import { ProjectLocator } from './project-locator' import { URL, fileURLToPath } from 'url' @@ -328,16 +328,19 @@ function testLocator({ fs, expected, settings, + options, }: { name: string fs: Storage settings?: Partial expected: any[] + options?: TestOptions }) { defineTest({ name, fs, prepare, + options, async handle({ search }) { let projects = await search(settings) From e76924688eba9666ab3c051af63d1f3ac2b046f0 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 18 Feb 2025 07:40:06 -0500 Subject: [PATCH 3/4] =?UTF-8?q?Try=20=E2=80=9Croots=E2=80=9D=20first=20ins?= =?UTF-8?q?tead=20of=20discarding=20non-roots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/project-locator.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/tailwindcss-language-server/src/project-locator.ts b/packages/tailwindcss-language-server/src/project-locator.ts index 64f7329b4..460b14233 100644 --- a/packages/tailwindcss-language-server/src/project-locator.ts +++ b/packages/tailwindcss-language-server/src/project-locator.ts @@ -427,11 +427,18 @@ export class ProjectLocator { if (indexPath && themePath) graph.connect(indexPath, themePath) if (indexPath && utilitiesPath) graph.connect(indexPath, utilitiesPath) - for (let root of graph.roots()) { - if (!root.meta) continue + // Sort the graph so potential "roots" appear first + // The entire concept of roots needs to be rethought because it's not always + // clear what the root of a project is. Even when imports are present a file + // may import a file that is the actual "root" of the project. + let roots = Array.from(graph.roots()) + + roots.sort((a, b) => { + return a.meta.root === b.meta.root ? 0 : a.meta.root ? -1 : 1 + }) - // This file is not eligible to act as a root of the CSS graph - if (root.meta.root === false) continue + for (let root of roots) { + if (!root.meta) continue let config: ConfigEntry = configs.remember(root.path, () => ({ source: 'css', From 63c4b08a1b4b8930b157b25e8befd18e0069f2c3 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 18 Feb 2025 07:35:47 -0500 Subject: [PATCH 4/4] Update changelog --- packages/vscode-tailwindcss/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index 0dd39795f..b5dc30a75 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -2,7 +2,7 @@ ## Prerelease -- Nothing yet! +- Fix detection when project contains stylesheets that import the "main" stylesheet ([#1218](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1218)) ## 0.14.5