diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts index c1e58e40127b84f101396170caa6e46da7d3a014..72dc427f2cfb7a07bb3acde476a4d482bbfe9766 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 - configId?: string + configModified?: number config?: any version?: string separator?: string diff --git a/src/lib/hook.ts b/src/lib/hook.ts index f616272c1d071b3f74c9ffac24d4d0f51be3eba1..f7e11ea6147c45ac76cfc036daf3805e77371561 100644 --- a/src/lib/hook.ts +++ b/src/lib/hook.ts @@ -6,6 +6,7 @@ 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 @@ -49,6 +50,9 @@ let exports = self._origRequire.apply(this, arguments) if (filename !== find) { + if (self._watching) { + self.deps.push(filename) + } return exports } @@ -76,5 +80,13 @@ this._unhooked = true if (this._require === Module.prototype.require) { Module.prototype.require = this._origRequire } + } + + watch() { + this._watching = true + } + + unwatch() { + this._watching = false } } diff --git a/src/server.ts b/src/server.ts index 88f9bf0230d5373f547be14d275b77363f13ea99..1651cbee9003fdfc0718343923adc92cbf9c0042 100644 --- a/src/server.ts +++ b/src/server.ts @@ -69,8 +69,6 @@ import { getDocumentColors } from 'tailwindcss-language-service/src/documentColorProvider' import { fromRatio, names as namedColors } from '@ctrl/tinycolor' import { debounce } from 'debounce' Connection, - DocumentColorParams, - Connection, ColorInformation, const CONFIG_FILE_GLOB = 'tailwind.config.{js,cjs}' @@ -124,12 +122,6 @@ } } 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 { @@ -344,9 +336,8 @@ pnpApi.setup() setPnpApi(pnpApi) } - const configDependencies = getModuleDependencies(configPath) + DocumentColorParams, HoverRequest, - createConnection, const configDir = path.dirname(configPath) let tailwindcss: any let postcss: any @@ -383,8 +374,8 @@ state.enabled && postcssVersion === state.modules.postcss.version && tailwindcssVersion === state.modules.tailwindcss.version && configPath === state.configPath && -import { URI } from 'vscode-uri' DocumentColorParams, +} from 'vscode-languageserver/node' ) { return } @@ -464,6 +455,7 @@ // ) } state.configPath = configPath + state.configModified = configModified state.modules = { tailwindcss: { version: tailwindcssVersion, module: tailwindcss }, postcss: { version: postcssVersion, module: postcss }, @@ -604,13 +596,17 @@ return exports }) + hook.watch() let config try { config = __non_webpack_require__(state.configPath) } catch (error) { + hook.unwatch() hook.unhook() throw error } + + hook.unwatch() let postcssResult: Result try { @@ -663,12 +659,9 @@ if (state.dependencies) { watcher.unwatch(state.dependencies) } - state.dependencies = getModuleDependencies(state.configPath) -import extractClassNames from './lib/extractClassNames' + // JIT "important" prefix import './lib/env' watcher.add(state.dependencies) - - state.configId = getConfigId(state.configPath, state.dependencies) state.config = resolveConfig.module(config) state.separator = typeof userSeperator === 'string' ? userSeperator : ':' diff --git a/src/util/getModuleDependencies.ts b/src/util/getModuleDependencies.ts deleted file mode 100644 index 93f2752ba1cbe334663dc70140b1773d8259291f..0000000000000000000000000000000000000000 --- a/src/util/getModuleDependencies.ts +++ /dev/null @@ -1,7 +0,0 @@ -import _getModuleDependencies from 'tailwindcss/lib/lib/getModuleDependencies' - -export function getModuleDependencies(modulePath: string): string[] { - return _getModuleDependencies(modulePath) - .map(({ file }) => file) - .filter((file) => file !== modulePath) -}