Skip to content

Commit

Permalink
Use one server to handle all folders in a workspace (#957)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thecrypticace committed Apr 24, 2024
1 parent 273f6c0 commit 9d7006d
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 393 deletions.
Expand Up @@ -26,7 +26,7 @@ let connection = createConnection(ProposedFeatures.all)
interceptLogs(console, connection)

process.on('unhandledRejection', (e: any) => {
console.error("Unhandled exception", e)
console.error('Unhandled exception', e)
})

let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument)
Expand Down
5 changes: 2 additions & 3 deletions packages/tailwindcss-language-server/src/projects.ts
Expand Up @@ -182,6 +182,7 @@ export async function createProjectService(
watchPatterns: (patterns: string[]) => void,
initialTailwindVersion: string,
getConfiguration: (uri?: string) => Promise<Settings>,
userLanguages: Record<string, string>,
): Promise<ProjectService> {
let enabled = false
const folder = projectConfig.folder
Expand All @@ -206,9 +207,7 @@ export async function createProjectService(
editor: {
connection,
folder,
userLanguages: params.initializationOptions?.userLanguages
? params.initializationOptions.userLanguages
: {},
userLanguages,
// TODO
capabilities: {
configuration: true,
Expand Down
14 changes: 13 additions & 1 deletion packages/tailwindcss-language-server/src/tw.ts
Expand Up @@ -42,7 +42,7 @@ import { equal } from '@tailwindcss/language-service/src/util/array'
import { CONFIG_GLOB, CSS_GLOB, PACKAGE_LOCK_GLOB } from './lib/constants'
import { clearRequireCache, isObject, changeAffectsFile } from './utils'
import { DocumentService } from './documents'
import { createProjectService, type ProjectService, DocumentSelectorPriority } from './projects'
import { createProjectService, type ProjectService } from './projects'
import { type SettingsCache, createSettingsCache } from './config'
import { readCssFile } from './util/css'
import { ProjectLocator, type ProjectConfig } from './project-locator'
Expand Down Expand Up @@ -163,6 +163,15 @@ export class TW {
let globalSettings = await this.settingsCache.get()
let ignore = globalSettings.tailwindCSS.files.exclude

// Get user languages for the given workspace folder
let folderSettings = await this.settingsCache.get(base)
let userLanguages = folderSettings.tailwindCSS.includeLanguages

// Fall back to settings defined in `initializationOptions` if invalid
if (!isObject(userLanguages)) {
userLanguages = this.initializeParams.initializationOptions?.userLanguages ?? {}
}

let cssFileConfigMap: Map<string, string> = new Map()
let configTailwindVersionMap: Map<string, string> = new Map()

Expand Down Expand Up @@ -489,6 +498,7 @@ export class TW {
this.initializeParams,
this.watchPatterns,
configTailwindVersionMap.get(projectConfig.configPath),
userLanguages,
),
),
)
Expand Down Expand Up @@ -604,6 +614,7 @@ export class TW {
params: InitializeParams,
watchPatterns: (patterns: string[]) => void,
tailwindVersion: string,
userLanguages: Record<string, string>,
): Promise<void> {
let key = String(this.projectCounter++)
const project = await createProjectService(
Expand All @@ -627,6 +638,7 @@ export class TW {
(patterns: string[]) => watchPatterns(patterns),
tailwindVersion,
this.settingsCache.get,
userLanguages,
)
this.projects.set(key, project)

Expand Down
@@ -1,5 +1,7 @@
{
"workspaces": ["packages/*"],
"workspaces": [
"packages/*"
],
"dependencies": {
"tailwindcss": "^4.0.0-alpha.12"
}
Expand Down

0 comments on commit 9d7006d

Please sign in to comment.