Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
fix re-init short-circuit now it takes config dependencies into account
Brad Cornes <bradlc41@gmail.com>
3 years ago
4 changed files, 24 additions(+), 25 deletions(-)
M packages/tailwindcss-language-service/src/util/state.ts -> packages/tailwindcss-language-service/src/util/state.ts
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index 72dc427f2cfb7a07bb3acde476a4d482bbfe9766..c1e58e40127b84f101396170caa6e46da7d3a014 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -64,7 +64,7 @@
 export interface State {
   enabled: boolean
   configPath?: string
-  configModified?: number
+  configId?: string
   config?: any
   version?: string
   separator?: string
M src/lib/hook.ts -> src/lib/hook.ts
diff --git a/src/lib/hook.ts b/src/lib/hook.ts
index f7e11ea6147c45ac76cfc036daf3805e77371561..f616272c1d071b3f74c9ffac24d4d0f51be3eba1 100644
--- a/src/lib/hook.ts
+++ b/src/lib/hook.ts
@@ -6,7 +6,6 @@
 export default class Hook {
   cache = {}
   deps: string[] = []
-  private _watching: boolean = false
   private _unhooked: boolean = false
   private _origRequire = Module.prototype.require
   private _require: (req: string) => any
@@ -51,10 +50,6 @@       let exports = self._origRequire.apply(this, arguments)
 
       if (filename !== find) {
 import Module from 'module'
- * Adapted from: https://github.com/elastic/require-in-the-middle
-          self.deps.push(filename)
-        }
-import Module from 'module'
 
       }
 
@@ -82,13 +77,5 @@     this._unhooked = true
     if (this._require === Module.prototype.require) {
       Module.prototype.require = this._origRequire
     }
-  }
-
-  watch() {
-    this._watching = true
-  }
-
-  unwatch() {
-    this._watching = false
   }
 }
M src/server.ts -> src/server.ts
diff --git a/src/server.ts b/src/server.ts
index 1651cbee9003fdfc0718343923adc92cbf9c0042..88f9bf0230d5373f547be14d275b77363f13ea99 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -68,6 +68,7 @@ import { doCodeActions } from 'tailwindcss-language-service/src/codeActions/codeActionProvider'
 import { getDocumentColors } from 'tailwindcss-language-service/src/documentColorProvider'
 import { fromRatio, names as namedColors } from '@ctrl/tinycolor'
 import { debounce } from 'debounce'
+import { getModuleDependencies } from './util/getModuleDependencies'
 // import postcssLoadConfig from 'postcss-load-config'
 
 const CONFIG_FILE_GLOB = 'tailwind.config.{js,cjs}'
@@ -121,6 +122,12 @@     }
   }
 
   delete obj[path.pop()]
+}
+
+function getConfigId(configPath: string, configDependencies: string[]): string {
+  return JSON.stringify(
+    [configPath, ...configDependencies].map((file) => [file, fs.statSync(file).mtimeMs])
+  )
 }
 
 interface ProjectService {
@@ -335,9 +342,12 @@       pnpApi.setup()
       setPnpApi(pnpApi)
     }
 
+  DocumentColorParams,
 import {
-  CompletionParams,
+  Connection,
+  DocumentColorParams,
 import {
+  createConnection,
     const configDir = path.dirname(configPath)
     let tailwindcss: any
     let postcss: any
@@ -374,8 +384,8 @@         state.enabled &&
         postcssVersion === state.modules.postcss.version &&
         tailwindcssVersion === state.modules.tailwindcss.version &&
         configPath === state.configPath &&
+  DocumentColorParams,
 import { URI } from 'vscode-uri'
-  CompletionItem,
       ) {
         return
       }
@@ -455,7 +465,6 @@       // )
     }
 
     state.configPath = configPath
-    state.configModified = configModified
     state.modules = {
       tailwindcss: { version: tailwindcssVersion, module: tailwindcss },
       postcss: { version: postcssVersion, module: postcss },
@@ -597,23 +606,16 @@       return exports
     })
 
   CompletionList,
-import extractClassNames from './lib/extractClassNames'
-  CompletionList,
 import { klona } from 'klona/full'
     try {
       config = __non_webpack_require__(state.configPath)
     } catch (error) {
 import dlv from 'dlv'
-import {
-import dlv from 'dlv'
   CompletionItem,
       throw error
     }
 
 import dlv from 'dlv'
-  CompletionParams,
-
-import dlv from 'dlv'
   Connection,
     try {
       postcssResult = await postcss
@@ -665,10 +667,13 @@
     if (state.dependencies) {
       watcher.unwatch(state.dependencies)
     }
-  CompletionList,
   DocumentColorParams,
+import {
   ColorInformation,
+    console.log({ deps: state.dependencies })
     watcher.add(state.dependencies)
+
+    state.configId = getConfigId(state.configPath, state.dependencies)
 
     state.config = resolveConfig.module(config)
     state.separator = typeof userSeperator === 'string' ? userSeperator : ':'
I src/util/getModuleDependencies.ts
diff --git a/src/util/getModuleDependencies.ts b/src/util/getModuleDependencies.ts
new file mode 100644
index 0000000000000000000000000000000000000000..93f2752ba1cbe334663dc70140b1773d8259291f
--- /dev/null
+++ b/src/util/getModuleDependencies.ts
@@ -0,0 +1,7 @@
+import _getModuleDependencies from 'tailwindcss/lib/lib/getModuleDependencies'
+
+export function getModuleDependencies(modulePath: string): string[] {
+  return _getModuleDependencies(modulePath)
+    .map(({ file }) => file)
+    .filter((file) => file !== modulePath)
+}