Skip to content

Fix matching files when config is not in the workspace root #1412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/tailwindcss-language-server/src/project-locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
Expand All @@ -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
Expand Down Expand Up @@ -132,6 +143,7 @@ export class ProjectLocator {
priority: DocumentSelectorPriority.USER_CONFIGURED,
pattern: selector,
})),
additionalSelectors: [],
tailwind,
}
}
Expand Down Expand Up @@ -214,6 +226,7 @@ export class ProjectLocator {
isUserConfigured: false,
configPath: config.path,
documentSelector: selectors,
additionalSelectors: [],
tailwind,
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-server/src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ export async function createProjectService(

state,
documentSelector() {
return documentSelector
return [...documentSelector, ...projectConfig.additionalSelectors]
},
tryInit,
async dispose() {
Expand Down
6 changes: 5 additions & 1 deletion packages/tailwindcss-language-server/src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface TestConfig<Extras extends {}, TestInput extends Record<string,
name: string
inputs?: TestInput[]

skipNPM?: boolean
fs?: Storage
debug?: boolean
prepare?(utils: TestUtils<TestInput>): Promise<Extras>
Expand Down Expand Up @@ -70,7 +71,10 @@ async function setup<T, I>(config: TestConfig<T, I>, input: I): Promise<TestUtil

if (config.fs) {
await prepareFileSystem(baseDir, config.fs)
await installDependencies(baseDir, config.fs)

if (!config.skipNPM) {
await installDependencies(baseDir, config.fs)
}
}

onTestFinished(async (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
39 changes: 39 additions & 0 deletions packages/tailwindcss-language-server/tests/env/v4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`<div class="bg-[#000]"></div>`,
})

// <div class="bg-[#000]"></div>
// ^
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 },
},
})
},
})
2 changes: 1 addition & 1 deletion packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down