From bb0aa260a3c218512362532b573e31f8ec0142af Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Sat, 14 Jun 2025 11:18:01 -0400 Subject: [PATCH 1/4] Fix types --- packages/tailwindcss-language-server/src/project-locator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tailwindcss-language-server/src/project-locator.ts b/packages/tailwindcss-language-server/src/project-locator.ts index 351302d4..2f002e35 100644 --- a/packages/tailwindcss-language-server/src/project-locator.ts +++ b/packages/tailwindcss-language-server/src/project-locator.ts @@ -22,10 +22,10 @@ export interface ProjectConfig { folder: string /** The path to the config file (if it exists) */ - configPath?: string + configPath: string /** The list of documents that are related to this project */ - documentSelector?: DocumentSelector[] + documentSelector: DocumentSelector[] /** Whether or not this project was explicitly defined by the user */ isUserConfigured: boolean From ddd708bf0dcfd47b1e32709727f88765baaf9ca6 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Sat, 14 Jun 2025 11:18:13 -0400 Subject: [PATCH 2/4] =?UTF-8?q?Fix=20matching=20behavior=20when=20config?= =?UTF-8?q?=20file=20isn=E2=80=99t=20in=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/project-locator.ts | 15 ++++++++++++++- .../tailwindcss-language-server/src/projects.ts | 2 +- packages/tailwindcss-language-server/src/tw.ts | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/tailwindcss-language-server/src/project-locator.ts b/packages/tailwindcss-language-server/src/project-locator.ts index 2f002e35..bec10290 100644 --- a/packages/tailwindcss-language-server/src/project-locator.ts +++ b/packages/tailwindcss-language-server/src/project-locator.ts @@ -27,6 +27,13 @@ export interface ProjectConfig { /** The list of documents that are related to this project */ documentSelector: DocumentSelector[] + /** + * Additional selectors that should be matched with this project + * + * These are *never* reset + */ + additionalSelectors: DocumentSelector[] + /** Whether or not this project was explicitly defined by the user */ isUserConfigured: boolean @@ -65,7 +72,7 @@ export class ProjectLocator { } if (projects.length === 1) { - projects[0].documentSelector.push({ + projects[0].additionalSelectors.push({ pattern: normalizePath(path.join(this.base, '**')), priority: DocumentSelectorPriority.ROOT_DIRECTORY, }) @@ -85,6 +92,10 @@ export class ProjectLocator { for (let selector of project.documentSelector) { selector.pattern = normalizeDriveLetter(selector.pattern) } + + for (let selector of project.additionalSelectors) { + selector.pattern = normalizeDriveLetter(selector.pattern) + } } return projects @@ -132,6 +143,7 @@ export class ProjectLocator { priority: DocumentSelectorPriority.USER_CONFIGURED, pattern: selector, })), + additionalSelectors: [], tailwind, } } @@ -214,6 +226,7 @@ export class ProjectLocator { isUserConfigured: false, configPath: config.path, documentSelector: selectors, + additionalSelectors: [], tailwind, } } diff --git a/packages/tailwindcss-language-server/src/projects.ts b/packages/tailwindcss-language-server/src/projects.ts index 0c54942c..1038d31b 100644 --- a/packages/tailwindcss-language-server/src/projects.ts +++ b/packages/tailwindcss-language-server/src/projects.ts @@ -1174,7 +1174,7 @@ export async function createProjectService( state, documentSelector() { - return documentSelector + return [...documentSelector, ...projectConfig.additionalSelectors] }, tryInit, async dispose() { diff --git a/packages/tailwindcss-language-server/src/tw.ts b/packages/tailwindcss-language-server/src/tw.ts index 6eb58553..07d3956a 100644 --- a/packages/tailwindcss-language-server/src/tw.ts +++ b/packages/tailwindcss-language-server/src/tw.ts @@ -351,7 +351,7 @@ export class TW { return { folder: workspace.folder, config: workspace.config.path, - selectors: workspace.documentSelector, + selectors: [...workspace.documentSelector, ...workspace.additionalSelectors], user: workspace.isUserConfigured, tailwind: workspace.tailwind, } From 81c2cae8d9a94755d4979d72fcc50f20bcb699e2 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Sat, 14 Jun 2025 11:31:43 -0400 Subject: [PATCH 3/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 94971656..f238d7d6 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -2,7 +2,7 @@ ## Prerelease -- Nothing yet! +- Fix matching files when config is not in the workspace root ([#1412](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1412)) ## 0.14.21 From e5871bd8469fe130e79bdede2477dfb339612bd3 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Sat, 14 Jun 2025 12:00:15 -0400 Subject: [PATCH 4/4] Add tests --- .../src/testing/index.ts | 6 ++- .../tests/env/v4.test.js | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss-language-server/src/testing/index.ts b/packages/tailwindcss-language-server/src/testing/index.ts index efce9fd2..f4737e19 100644 --- a/packages/tailwindcss-language-server/src/testing/index.ts +++ b/packages/tailwindcss-language-server/src/testing/index.ts @@ -32,6 +32,7 @@ export interface TestConfig): Promise @@ -70,7 +71,10 @@ async function setup(config: TestConfig, input: I): Promise { diff --git a/packages/tailwindcss-language-server/tests/env/v4.test.js b/packages/tailwindcss-language-server/tests/env/v4.test.js index af3916cf..6104ef7a 100644 --- a/packages/tailwindcss-language-server/tests/env/v4.test.js +++ b/packages/tailwindcss-language-server/tests/env/v4.test.js @@ -856,3 +856,42 @@ defineTest({ }) }, }) + +defineTest({ + name: 'Matches files in a workspace when only one config exists and is nested in a package', + skipNPM: true, + fs: { + 'some-dir/package.json': json`{"type": "commonjs"}`, + 'some-dir/tailwind.config.js': js` + module.exports = { content: [] } + `, + }, + prepare: async ({ root }) => ({ client: await createClient({ root }) }), + handle: async ({ client }) => { + let doc = await client.open({ + name: 'files/index.html', + lang: 'html', + text: html`
`, + }) + + //
+ // ^ + let hover = await doc.hover({ line: 0, character: 13 }) + + expect(hover).toEqual({ + contents: { + language: 'css', + value: dedent` + .bg-\[\#000\] { + --tw-bg-opacity: 1; + background-color: rgb(0 0 0 / var(--tw-bg-opacity, 1)) /* #000000 */; + } + `, + }, + range: { + start: { line: 0, character: 12 }, + end: { line: 0, character: 21 }, + }, + }) + }, +})