Skip to content

Use one server to handle all folders in a workspace #957

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 9 commits into from
Apr 24, 2024
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"workspaces": ["packages/*"],
"workspaces": [
"packages/*"
],
"dependencies": {
"tailwindcss": "^4.0.0-alpha.12"
}
Expand Down
Loading