1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index 7fe1bd9c1362bbf6a9d73e9e81fe7a0585c29893..99bb98946f010e802c6ea1425a2afe4b692a73bb 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -177,6 +177,7 @@ }
}
interface ProjectService {
+ projectConfig: ProjectConfig
enabled: () => boolean
enable: () => void
documentSelector: () => Array<DocumentSelector>
@@ -361,6 +362,7 @@ return patterns
}
async function createProjectService(
+ projectKey: string,
projectConfig: ProjectConfig,
connection: Connection,
params: InitializeParams,
@@ -1064,6 +1066,7 @@ updateCapabilities()
}
return {
+ projectConfig,
enabled() {
return enabled
},
@@ -1117,7 +1120,7 @@ return {
isIncomplete: result.isIncomplete,
items: result.items.map((item) => ({
...item,
- data: { projectKey: JSON.stringify(projectConfig), originalData: item.data },
+ data: { projectKey, originalData: item.data },
})),
}
}, null)
@@ -1561,6 +1564,7 @@ private initialized = false
private lspHandlersAdded = false
private workspaces: Map<string, { name: string; workspaceFsPath: string }>
private projects: Map<string, ProjectService>
+ private projectCounter: number
private documentService: DocumentService
public initializeParams: InitializeParams
private registrations: Promise<BulkUnregistration>
@@ -1572,6 +1576,7 @@ constructor(private connection: Connection) {
this.documentService = new DocumentService(this.connection)
this.workspaces = new Map()
this.projects = new Map()
+ this.projectCounter = 0
}
async init(): Promise<void> {
@@ -1754,19 +1759,18 @@ }
let isPackageFile = minimatch(normalizedFilename, `**/${PACKAGE_LOCK_GLOB}`, { dot: true })
if (isPackageFile) {
- for (let [key] of this.projects) {
- let projectConfig = JSON.parse(key) as ProjectConfig
+ for (let [, project] of this.projects) {
let twVersion = require('tailwindcss/package.json').version
try {
let v = require(resolveFrom(
- path.dirname(projectConfig.configPath),
+ path.dirname(project.projectConfig.configPath),
'tailwindcss/package.json'
)).version
if (typeof v === 'string') {
twVersion = v
}
} catch {}
- if (configTailwindVersionMap.get(projectConfig.configPath) !== twVersion) {
+ if (configTailwindVersionMap.get(project.projectConfig.configPath) !== twVersion) {
needsRestart = true
break changeLoop
}
@@ -1798,11 +1802,10 @@ needsRestart = true
break
}
- for (let [key] of this.projects) {
- let projectConfig = JSON.parse(key) as ProjectConfig
+ for (let [, project] of this.projects) {
if (
change.type === FileChangeType.Deleted &&
- changeAffectsFile(normalizedFilename, [projectConfig.configPath])
+ changeAffectsFile(normalizedFilename, [project.projectConfig.configPath])
) {
needsRestart = true
break changeLoop
@@ -2017,31 +2020,29 @@ params: InitializeParams,
watchPatterns: (patterns: string[]) => void,
tailwindVersion: string
): Promise<void> {
- let key = JSON.stringify(projectConfig)
-
- if (!this.projects.has(key)) {
- const project = await createProjectService(
- projectConfig,
- this.connection,
- params,
- this.documentService,
- () => this.updateCapabilities(),
- () => {
- for (let document of this.documentService.getAllDocuments()) {
- let project = this.getProject(document)
- if (project && !project.enabled()) {
- project.enable()
- project.tryInit()
- break
- }
+ let key = String(this.projectCounter++)
+ const project = await createProjectService(
+ key,
+ projectConfig,
+ this.connection,
+ params,
+ this.documentService,
+ () => this.updateCapabilities(),
+ () => {
+ for (let document of this.documentService.getAllDocuments()) {
+ let project = this.getProject(document)
+ if (project && !project.enabled()) {
+ project.enable()
+ project.tryInit()
+ break
}
- },
- () => this.refreshDiagnostics(),
- (patterns: string[]) => watchPatterns(patterns),
- tailwindVersion
- )
- this.projects.set(key, project)
- }
+ }
+ },
+ () => this.refreshDiagnostics(),
+ (patterns: string[]) => watchPatterns(patterns),
+ tailwindVersion
+ )
+ this.projects.set(key, project)
}
private refreshDiagnostics() {
@@ -2104,9 +2105,8 @@ let fallbackProject: ProjectService
let matchedProject: ProjectService
let matchedPriority: number = Infinity
- for (let [key, project] of this.projects) {
- let projectConfig = JSON.parse(key) as ProjectConfig
- if (projectConfig.configPath) {
+ for (let [, project] of this.projects) {
+ if (project.projectConfig.configPath) {
let documentSelector = project
.documentSelector()
.concat()
|