Skip to content

Commit ddd708b

Browse files
committed
Fix matching behavior when config file isn’t in root
1 parent bb0aa26 commit ddd708b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

packages/tailwindcss-language-server/src/project-locator.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export interface ProjectConfig {
2727
/** The list of documents that are related to this project */
2828
documentSelector: DocumentSelector[]
2929

30+
/**
31+
* Additional selectors that should be matched with this project
32+
*
33+
* These are *never* reset
34+
*/
35+
additionalSelectors: DocumentSelector[]
36+
3037
/** Whether or not this project was explicitly defined by the user */
3138
isUserConfigured: boolean
3239

@@ -65,7 +72,7 @@ export class ProjectLocator {
6572
}
6673

6774
if (projects.length === 1) {
68-
projects[0].documentSelector.push({
75+
projects[0].additionalSelectors.push({
6976
pattern: normalizePath(path.join(this.base, '**')),
7077
priority: DocumentSelectorPriority.ROOT_DIRECTORY,
7178
})
@@ -85,6 +92,10 @@ export class ProjectLocator {
8592
for (let selector of project.documentSelector) {
8693
selector.pattern = normalizeDriveLetter(selector.pattern)
8794
}
95+
96+
for (let selector of project.additionalSelectors) {
97+
selector.pattern = normalizeDriveLetter(selector.pattern)
98+
}
8899
}
89100

90101
return projects
@@ -132,6 +143,7 @@ export class ProjectLocator {
132143
priority: DocumentSelectorPriority.USER_CONFIGURED,
133144
pattern: selector,
134145
})),
146+
additionalSelectors: [],
135147
tailwind,
136148
}
137149
}
@@ -214,6 +226,7 @@ export class ProjectLocator {
214226
isUserConfigured: false,
215227
configPath: config.path,
216228
documentSelector: selectors,
229+
additionalSelectors: [],
217230
tailwind,
218231
}
219232
}

packages/tailwindcss-language-server/src/projects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ export async function createProjectService(
11741174

11751175
state,
11761176
documentSelector() {
1177-
return documentSelector
1177+
return [...documentSelector, ...projectConfig.additionalSelectors]
11781178
},
11791179
tryInit,
11801180
async dispose() {

packages/tailwindcss-language-server/src/tw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export class TW {
351351
return {
352352
folder: workspace.folder,
353353
config: workspace.config.path,
354-
selectors: workspace.documentSelector,
354+
selectors: [...workspace.documentSelector, ...workspace.additionalSelectors],
355355
user: workspace.isUserConfigured,
356356
tailwind: workspace.tailwind,
357357
}

0 commit comments

Comments
 (0)