Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Reduce size of project key in completion items
Brad Cornes <hello@bradley.dev>
2 years ago
1 changed files, 35 additions(+), 35 deletions(-)
M packages/tailwindcss-language-server/src/server.ts -> packages/tailwindcss-language-server/src/server.ts
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()