Skip to content

Commit 9d7006d

Browse files
Use one server to handle all folders in a workspace (#957)
* Fix strict mode typescript errors * Refactor * Load user languages when booting It makes more sense for our server to ask for them like we do all other config options rather than expecting them to be passed in during initialization * Only start one server for all workspace folders * Check all workspace folders when booting the server This is a bit of a behavioral change but if _any_ folder in your current workspace might need the language server when we’ll boot it. We do still wait for an open document currently. * Remove note * Remove unused expect error directive It’ll need to come back once I upgrade TypeScript * Fix folder count check * Run prettier
1 parent 273f6c0 commit 9d7006d

File tree

7 files changed

+407
-393
lines changed

7 files changed

+407
-393
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let connection = createConnection(ProposedFeatures.all)
2626
interceptLogs(console, connection)
2727

2828
process.on('unhandledRejection', (e: any) => {
29-
console.error("Unhandled exception", e)
29+
console.error('Unhandled exception', e)
3030
})
3131

3232
let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument)

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export async function createProjectService(
182182
watchPatterns: (patterns: string[]) => void,
183183
initialTailwindVersion: string,
184184
getConfiguration: (uri?: string) => Promise<Settings>,
185+
userLanguages: Record<string, string>,
185186
): Promise<ProjectService> {
186187
let enabled = false
187188
const folder = projectConfig.folder
@@ -206,9 +207,7 @@ export async function createProjectService(
206207
editor: {
207208
connection,
208209
folder,
209-
userLanguages: params.initializationOptions?.userLanguages
210-
? params.initializationOptions.userLanguages
211-
: {},
210+
userLanguages,
212211
// TODO
213212
capabilities: {
214213
configuration: true,

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { equal } from '@tailwindcss/language-service/src/util/array'
4242
import { CONFIG_GLOB, CSS_GLOB, PACKAGE_LOCK_GLOB } from './lib/constants'
4343
import { clearRequireCache, isObject, changeAffectsFile } from './utils'
4444
import { DocumentService } from './documents'
45-
import { createProjectService, type ProjectService, DocumentSelectorPriority } from './projects'
45+
import { createProjectService, type ProjectService } from './projects'
4646
import { type SettingsCache, createSettingsCache } from './config'
4747
import { readCssFile } from './util/css'
4848
import { ProjectLocator, type ProjectConfig } from './project-locator'
@@ -163,6 +163,15 @@ export class TW {
163163
let globalSettings = await this.settingsCache.get()
164164
let ignore = globalSettings.tailwindCSS.files.exclude
165165

166+
// Get user languages for the given workspace folder
167+
let folderSettings = await this.settingsCache.get(base)
168+
let userLanguages = folderSettings.tailwindCSS.includeLanguages
169+
170+
// Fall back to settings defined in `initializationOptions` if invalid
171+
if (!isObject(userLanguages)) {
172+
userLanguages = this.initializeParams.initializationOptions?.userLanguages ?? {}
173+
}
174+
166175
let cssFileConfigMap: Map<string, string> = new Map()
167176
let configTailwindVersionMap: Map<string, string> = new Map()
168177

@@ -489,6 +498,7 @@ export class TW {
489498
this.initializeParams,
490499
this.watchPatterns,
491500
configTailwindVersionMap.get(projectConfig.configPath),
501+
userLanguages,
492502
),
493503
),
494504
)
@@ -604,6 +614,7 @@ export class TW {
604614
params: InitializeParams,
605615
watchPatterns: (patterns: string[]) => void,
606616
tailwindVersion: string,
617+
userLanguages: Record<string, string>,
607618
): Promise<void> {
608619
let key = String(this.projectCounter++)
609620
const project = await createProjectService(
@@ -627,6 +638,7 @@ export class TW {
627638
(patterns: string[]) => watchPatterns(patterns),
628639
tailwindVersion,
629640
this.settingsCache.get,
641+
userLanguages,
630642
)
631643
this.projects.set(key, project)
632644

packages/tailwindcss-language-server/tests/fixtures/v4/workspaces/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"workspaces": ["packages/*"],
2+
"workspaces": [
3+
"packages/*"
4+
],
35
"dependencies": {
46
"tailwindcss": "^4.0.0-alpha.12"
57
}

0 commit comments

Comments
 (0)