diff --git a/packages/tailwindcss-language-server/src/project-locator.ts b/packages/tailwindcss-language-server/src/project-locator.ts index 351302d4..bec10290 100644 --- a/packages/tailwindcss-language-server/src/project-locator.ts +++ b/packages/tailwindcss-language-server/src/project-locator.ts @@ -22,10 +22,17 @@ 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[] + + /** + * 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/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/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, } 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 }, + }, + }) + }, +}) 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