Skip to content

Commit 8685037

Browse files
committed
Reduce size of project key in completion items
1 parent 00fb8ec commit 8685037

File tree

1 file changed

+35
-35
lines changed
  • packages/tailwindcss-language-server/src

1 file changed

+35
-35
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ function firstOptional<T>(...options: Array<() => T>): T | undefined {
177177
}
178178

179179
interface ProjectService {
180+
projectConfig: ProjectConfig
180181
enabled: () => boolean
181182
enable: () => void
182183
documentSelector: () => Array<DocumentSelector>
@@ -361,6 +362,7 @@ function getWatchPatternsForFile(file: string): string[] {
361362
}
362363

363364
async function createProjectService(
365+
projectKey: string,
364366
projectConfig: ProjectConfig,
365367
connection: Connection,
366368
params: InitializeParams,
@@ -1064,6 +1066,7 @@ async function createProjectService(
10641066
}
10651067

10661068
return {
1069+
projectConfig,
10671070
enabled() {
10681071
return enabled
10691072
},
@@ -1117,7 +1120,7 @@ async function createProjectService(
11171120
isIncomplete: result.isIncomplete,
11181121
items: result.items.map((item) => ({
11191122
...item,
1120-
data: { projectKey: JSON.stringify(projectConfig), originalData: item.data },
1123+
data: { projectKey, originalData: item.data },
11211124
})),
11221125
}
11231126
}, null)
@@ -1561,6 +1564,7 @@ class TW {
15611564
private lspHandlersAdded = false
15621565
private workspaces: Map<string, { name: string; workspaceFsPath: string }>
15631566
private projects: Map<string, ProjectService>
1567+
private projectCounter: number
15641568
private documentService: DocumentService
15651569
public initializeParams: InitializeParams
15661570
private registrations: Promise<BulkUnregistration>
@@ -1572,6 +1576,7 @@ class TW {
15721576
this.documentService = new DocumentService(this.connection)
15731577
this.workspaces = new Map()
15741578
this.projects = new Map()
1579+
this.projectCounter = 0
15751580
}
15761581

15771582
async init(): Promise<void> {
@@ -1754,19 +1759,18 @@ class TW {
17541759

17551760
let isPackageFile = minimatch(normalizedFilename, `**/${PACKAGE_LOCK_GLOB}`, { dot: true })
17561761
if (isPackageFile) {
1757-
for (let [key] of this.projects) {
1758-
let projectConfig = JSON.parse(key) as ProjectConfig
1762+
for (let [, project] of this.projects) {
17591763
let twVersion = require('tailwindcss/package.json').version
17601764
try {
17611765
let v = require(resolveFrom(
1762-
path.dirname(projectConfig.configPath),
1766+
path.dirname(project.projectConfig.configPath),
17631767
'tailwindcss/package.json'
17641768
)).version
17651769
if (typeof v === 'string') {
17661770
twVersion = v
17671771
}
17681772
} catch {}
1769-
if (configTailwindVersionMap.get(projectConfig.configPath) !== twVersion) {
1773+
if (configTailwindVersionMap.get(project.projectConfig.configPath) !== twVersion) {
17701774
needsRestart = true
17711775
break changeLoop
17721776
}
@@ -1798,11 +1802,10 @@ class TW {
17981802
break
17991803
}
18001804

1801-
for (let [key] of this.projects) {
1802-
let projectConfig = JSON.parse(key) as ProjectConfig
1805+
for (let [, project] of this.projects) {
18031806
if (
18041807
change.type === FileChangeType.Deleted &&
1805-
changeAffectsFile(normalizedFilename, [projectConfig.configPath])
1808+
changeAffectsFile(normalizedFilename, [project.projectConfig.configPath])
18061809
) {
18071810
needsRestart = true
18081811
break changeLoop
@@ -2017,31 +2020,29 @@ class TW {
20172020
watchPatterns: (patterns: string[]) => void,
20182021
tailwindVersion: string
20192022
): Promise<void> {
2020-
let key = JSON.stringify(projectConfig)
2021-
2022-
if (!this.projects.has(key)) {
2023-
const project = await createProjectService(
2024-
projectConfig,
2025-
this.connection,
2026-
params,
2027-
this.documentService,
2028-
() => this.updateCapabilities(),
2029-
() => {
2030-
for (let document of this.documentService.getAllDocuments()) {
2031-
let project = this.getProject(document)
2032-
if (project && !project.enabled()) {
2033-
project.enable()
2034-
project.tryInit()
2035-
break
2036-
}
2023+
let key = String(this.projectCounter++)
2024+
const project = await createProjectService(
2025+
key,
2026+
projectConfig,
2027+
this.connection,
2028+
params,
2029+
this.documentService,
2030+
() => this.updateCapabilities(),
2031+
() => {
2032+
for (let document of this.documentService.getAllDocuments()) {
2033+
let project = this.getProject(document)
2034+
if (project && !project.enabled()) {
2035+
project.enable()
2036+
project.tryInit()
2037+
break
20372038
}
2038-
},
2039-
() => this.refreshDiagnostics(),
2040-
(patterns: string[]) => watchPatterns(patterns),
2041-
tailwindVersion
2042-
)
2043-
this.projects.set(key, project)
2044-
}
2039+
}
2040+
},
2041+
() => this.refreshDiagnostics(),
2042+
(patterns: string[]) => watchPatterns(patterns),
2043+
tailwindVersion
2044+
)
2045+
this.projects.set(key, project)
20452046
}
20462047

20472048
private refreshDiagnostics() {
@@ -2104,9 +2105,8 @@ class TW {
21042105
let matchedProject: ProjectService
21052106
let matchedPriority: number = Infinity
21062107

2107-
for (let [key, project] of this.projects) {
2108-
let projectConfig = JSON.parse(key) as ProjectConfig
2109-
if (projectConfig.configPath) {
2108+
for (let [, project] of this.projects) {
2109+
if (project.projectConfig.configPath) {
21102110
let documentSelector = project
21112111
.documentSelector()
21122112
.concat()

0 commit comments

Comments
 (0)