Reduce size of project key in completion items

master
Brad Cornes 2023-01-16 19:28:49 +00:00
parent 00fb8ecb9e
commit 86850376db
1 changed files with 35 additions and 35 deletions

View File

@ -177,6 +177,7 @@ function firstOptional<T>(...options: Array<() => T>): T | undefined {
} }
interface ProjectService { interface ProjectService {
projectConfig: ProjectConfig
enabled: () => boolean enabled: () => boolean
enable: () => void enable: () => void
documentSelector: () => Array<DocumentSelector> documentSelector: () => Array<DocumentSelector>
@ -361,6 +362,7 @@ function getWatchPatternsForFile(file: string): string[] {
} }
async function createProjectService( async function createProjectService(
projectKey: string,
projectConfig: ProjectConfig, projectConfig: ProjectConfig,
connection: Connection, connection: Connection,
params: InitializeParams, params: InitializeParams,
@ -1064,6 +1066,7 @@ async function createProjectService(
} }
return { return {
projectConfig,
enabled() { enabled() {
return enabled return enabled
}, },
@ -1117,7 +1120,7 @@ async function createProjectService(
isIncomplete: result.isIncomplete, isIncomplete: result.isIncomplete,
items: result.items.map((item) => ({ items: result.items.map((item) => ({
...item, ...item,
data: { projectKey: JSON.stringify(projectConfig), originalData: item.data }, data: { projectKey, originalData: item.data },
})), })),
} }
}, null) }, null)
@ -1561,6 +1564,7 @@ class TW {
private lspHandlersAdded = false private lspHandlersAdded = false
private workspaces: Map<string, { name: string; workspaceFsPath: string }> private workspaces: Map<string, { name: string; workspaceFsPath: string }>
private projects: Map<string, ProjectService> private projects: Map<string, ProjectService>
private projectCounter: number
private documentService: DocumentService private documentService: DocumentService
public initializeParams: InitializeParams public initializeParams: InitializeParams
private registrations: Promise<BulkUnregistration> private registrations: Promise<BulkUnregistration>
@ -1572,6 +1576,7 @@ class TW {
this.documentService = new DocumentService(this.connection) this.documentService = new DocumentService(this.connection)
this.workspaces = new Map() this.workspaces = new Map()
this.projects = new Map() this.projects = new Map()
this.projectCounter = 0
} }
async init(): Promise<void> { async init(): Promise<void> {
@ -1754,19 +1759,18 @@ class TW {
let isPackageFile = minimatch(normalizedFilename, `**/${PACKAGE_LOCK_GLOB}`, { dot: true }) let isPackageFile = minimatch(normalizedFilename, `**/${PACKAGE_LOCK_GLOB}`, { dot: true })
if (isPackageFile) { if (isPackageFile) {
for (let [key] of this.projects) { for (let [, project] of this.projects) {
let projectConfig = JSON.parse(key) as ProjectConfig
let twVersion = require('tailwindcss/package.json').version let twVersion = require('tailwindcss/package.json').version
try { try {
let v = require(resolveFrom( let v = require(resolveFrom(
path.dirname(projectConfig.configPath), path.dirname(project.projectConfig.configPath),
'tailwindcss/package.json' 'tailwindcss/package.json'
)).version )).version
if (typeof v === 'string') { if (typeof v === 'string') {
twVersion = v twVersion = v
} }
} catch {} } catch {}
if (configTailwindVersionMap.get(projectConfig.configPath) !== twVersion) { if (configTailwindVersionMap.get(project.projectConfig.configPath) !== twVersion) {
needsRestart = true needsRestart = true
break changeLoop break changeLoop
} }
@ -1798,11 +1802,10 @@ class TW {
break break
} }
for (let [key] of this.projects) { for (let [, project] of this.projects) {
let projectConfig = JSON.parse(key) as ProjectConfig
if ( if (
change.type === FileChangeType.Deleted && change.type === FileChangeType.Deleted &&
changeAffectsFile(normalizedFilename, [projectConfig.configPath]) changeAffectsFile(normalizedFilename, [project.projectConfig.configPath])
) { ) {
needsRestart = true needsRestart = true
break changeLoop break changeLoop
@ -2017,10 +2020,9 @@ class TW {
watchPatterns: (patterns: string[]) => void, watchPatterns: (patterns: string[]) => void,
tailwindVersion: string tailwindVersion: string
): Promise<void> { ): Promise<void> {
let key = JSON.stringify(projectConfig) let key = String(this.projectCounter++)
if (!this.projects.has(key)) {
const project = await createProjectService( const project = await createProjectService(
key,
projectConfig, projectConfig,
this.connection, this.connection,
params, params,
@ -2042,7 +2044,6 @@ class TW {
) )
this.projects.set(key, project) this.projects.set(key, project)
} }
}
private refreshDiagnostics() { private refreshDiagnostics() {
for (let doc of this.documentService.getAllDocuments()) { for (let doc of this.documentService.getAllDocuments()) {
@ -2104,9 +2105,8 @@ class TW {
let matchedProject: ProjectService let matchedProject: ProjectService
let matchedPriority: number = Infinity let matchedPriority: number = Infinity
for (let [key, project] of this.projects) { for (let [, project] of this.projects) {
let projectConfig = JSON.parse(key) as ProjectConfig if (project.projectConfig.configPath) {
if (projectConfig.configPath) {
let documentSelector = project let documentSelector = project
.documentSelector() .documentSelector()
.concat() .concat()