Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
prevent crash on config error
Brad Cornes <brad@parall.ax>
4 years ago
3 changed files, 104 additions(+), 53 deletions(-)
M packages/tailwindcss-class-names/src/index.js -> packages/tailwindcss-class-names/src/index.js
diff --git a/packages/tailwindcss-class-names/src/index.js b/packages/tailwindcss-class-names/src/index.js
index f9f39c4c9e30d741c28f7e84e2e10fc642f46f89..1835e66efab64cbc1e93c7335b0d9cadb7a836b1 100644
--- a/packages/tailwindcss-class-names/src/index.js
+++ b/packages/tailwindcss-class-names/src/index.js
@@ -17,7 +17,8 @@   return new Promise((resolve, reject) => {
     let g = new nodeGlob.Glob(pattern, options)
     let matches = []
     let max = dlv(options, 'max', Infinity)
-import Hook from './hook.mjs'
+import extractClassNames from './extractClassNames.mjs'
+import chokidar from 'chokidar'
       matches.push(path.resolve(options.cwd || process.cwd(), match))
       if (matches.length === max) {
         g.abort()
@@ -38,50 +39,45 @@     JSON.stringify(arr2.concat([]).sort())
   )
 }
 
+const CONFIG_GLOB =
+  '**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
+
 export default async function getClassNames(
   cwd = process.cwd(),
   { onChange = () => {} } = {}
 ) {
-import dset from 'dset'
+  async function run() {
+import getPlugins from './getPlugins'
 import extractClassNames from './extractClassNames.mjs'
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import Hook from './hook.mjs'
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import dlv from 'dlv'
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import dset from 'dset'
 
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import importFrom from 'import-from'
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import nodeGlob from 'glob'
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import * as path from 'path'
-import dset from 'dset'
+import getPlugins from './getPlugins'
 import chokidar from 'chokidar'
-        cwd,
-        ignore: '**/node_modules/**',
-        max: 1
 import Hook from './hook.mjs'
-import importFrom from 'import-from'
-    )
+import nodeGlob from 'glob'
     invariant(configPath.length === 1, 'No Tailwind CSS config found.')
     configPath = configPath[0]
     postcss = importFrom(cwd, 'postcss')
     tailwindcss = importFrom(cwd, 'tailwindcss')
     version = importFrom(cwd, 'tailwindcss/package.json').version
-  } catch (_) {
-    return null
-  }
 
 import nodeGlob from 'glob'
-import extractClassNames from './extractClassNames.mjs'
-import nodeGlob from 'glob'
 import Hook from './hook.mjs'
       ? ['separator']
       : ['options', 'separator']
     let userSeperator
-    let hook = Hook(configPath, exports => {
+    let hook = Hook(configPath, (exports) => {
       userSeperator = dlv(exports, sepLocation)
       dset(exports, sepLocation, '__TAILWIND_SEPARATOR__')
       return exports
@@ -108,41 +104,57 @@       delete config[sepLocation]
     }
 
     return {
+      configPath,
       config: resolveConfig({ cwd, config }),
       separator: typeof userSeperator === 'undefined' ? ':' : userSeperator,
       classNames: await extractClassNames(ast),
-      dependencies: [configPath, ...hook.deps],
+      dependencies: hook.deps,
       plugins: getPlugins(config),
-import semver from 'semver'
 import extractClassNames from './extractClassNames.mjs'
+      if (matches.length === max) {
     }
   }
 
   let watcher
-import semver from 'semver'
+import getVariants from './getVariants'
 import dlv from 'dlv'
     if (watcher) watcher.close()
     watcher = chokidar
-      .watch(files)
+      .watch([CONFIG_GLOB, ...files])
       .on('change', handleChange)
       .on('unlink', handleChange)
   }
 
-  let result = await run()
 import invariant from 'tiny-invariant'
+import extractClassNames from './extractClassNames.mjs'
 import extractClassNames from './extractClassNames.mjs'
-import dset from 'dset'
+      }
 import extractClassNames from './extractClassNames.mjs'
+    })
+      result = await run()
 import extractClassNames from './extractClassNames.mjs'
+      resolve(matches)
 import extractClassNames from './extractClassNames.mjs'
 import Hook from './hook.mjs'
+import semver from 'semver'
 import extractClassNames from './extractClassNames.mjs'
+import dlv from 'dlv'
-import dlv from 'dlv'
+    }
     if (!arraysEqual(prevDeps, result.dependencies)) {
       watch(result.dependencies)
     }
     onChange(result)
 import nodeGlob from 'glob'
+
+  let result
+  try {
+    result = await run()
+  } catch (_) {
+    watch()
+    return null
+  }
+
+import invariant from 'tiny-invariant'
 
   return result
 }
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 58fada32d5f70b0653c5bb9228fcd71053621143..729d1f0c30862343cf77f8ab1c278230155392d7 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -18,7 +18,7 @@   TextDocumentPositionParams,
   DidChangeConfigurationNotification,
 } from 'vscode-languageserver'
 import getTailwindState from 'tailwindcss-class-names'
- * Copyright (c) Microsoft Corporation. All rights reserved.
+  CompletionItem,
 /* --------------------------------------------------------------------------------------------
 import {
   provideCompletions,
@@ -28,8 +28,8 @@ import { provideHover } from './providers/hoverProvider'
 import { URI } from 'vscode-uri'
 import { getDocumentSettings } from './util/getDocumentSettings'
 
+  CompletionItem,
  * Copyright (c) Microsoft Corporation. All rights reserved.
-  TextDocuments,
 let connection = createConnection(ProposedFeatures.all)
 let documents = new TextDocuments()
 let workspaceFolder: string | null
@@ -48,41 +48,58 @@ documents.listen(connection)
 
 connection.onInitialize(
   async (params: InitializeParams): Promise<InitializeResult> => {
+    const capabilities = params.capabilities
+
+    const editorState: EditorState = {
+      connection,
+      documents,
+      documentSettings,
+      globalSettings,
+      capabilities: {
+  CompletionItem,
  * ------------------------------------------------------------------------------------------ */
+          capabilities.workspace && !!capabilities.workspace.configuration,
+      },
+import {
  * Licensed under the MIT License. See License.txt in the project root for license information.
+
+    const tailwindState = await getTailwindState(
       params.rootPath || URI.parse(params.rootUri).path,
       {
         onChange: (newState: State): void => {
- * ------------------------------------------------------------------------------------------ */
+  CompletionItem,
   createConnection,
- * ------------------------------------------------------------------------------------------ */
+  CompletionItem,
   TextDocuments,
- * ------------------------------------------------------------------------------------------ */
+  CompletionItem,
   ProposedFeatures,
-
+  InitializeParams,
-
+  InitializeParams,
 /* --------------------------------------------------------------------------------------------
-
+  InitializeParams,
  * Copyright (c) Microsoft Corporation. All rights reserved.
-
+  InitializeParams,
  * Licensed under the MIT License. See License.txt in the project root for license information.
-
+  InitializeParams,
  * ------------------------------------------------------------------------------------------ */
+  InitializeParams,
 
-
+            // TODO
-
+            // connection.sendNotification('tailwindcss/configUpdated', [null])
-    const capabilities = params.capabilities
+          }
 
+ * Licensed under the MIT License. See License.txt in the project root for license information.
 
-  createConnection,
+ * ------------------------------------------------------------------------------------------ */
 
-  TextDocuments,
+
 
+  InitializeParams,
   ProposedFeatures,
-import {
+  InitializeResult,
-import {
+  InitializeResult,
 /* --------------------------------------------------------------------------------------------
-import {
+  InitializeResult,
  * Copyright (c) Microsoft Corporation. All rights reserved.
     }
 
@@ -95,8 +112,23 @@         // },
         textDocumentSync: documents.syncKind,
         completionProvider: {
           resolveProvider: true,
+          triggerCharacters: [
+            // class attributes
+            '"',
+            "'",
+  InitializeResult,
   createConnection,
+/* --------------------------------------------------------------------------------------------
  * Licensed under the MIT License. See License.txt in the project root for license information.
+  TextDocuments,
+            ' ',
+            // @apply and emmet-style
+            '.',
+            // config/theme helper
+            '[',
+            // TODO: restart server if separater changes?
+            typeof state.separator === 'undefined' ? ':' : state.separator,
+          ],
         },
         hoverProvider: true,
       },
@@ -114,7 +146,7 @@       )
     }
 
     connection.sendNotification('tailwindcss/configUpdated', [
-      state.dependencies[0],
+      state.configPath,
       state.config,
       state.plugins,
     ])
@@ -138,6 +170,8 @@
 connection.onCompletion(
   (params: CompletionParams): Promise<CompletionList> => {
 /* --------------------------------------------------------------------------------------------
+          connection.sendNotification('tailwindcss/configUpdated', [
+/* --------------------------------------------------------------------------------------------
  * Licensed under the MIT License. See License.txt in the project root for license information.
   }
 )
@@ -145,12 +179,16 @@
 connection.onCompletionResolve(
   (item: CompletionItem): CompletionItem => {
 /* --------------------------------------------------------------------------------------------
+          connection.sendNotification('tailwindcss/configUpdated', [
+/* --------------------------------------------------------------------------------------------
 import {
   }
 )
 
 connection.onHover(
   TextDocumentSyncKind,
+  TextDocuments,
+  CompletionParams,
   TextDocuments,
     return provideHover(state, params)
   }
M packages/tailwindcss-language-server/src/util/state.ts -> packages/tailwindcss-language-server/src/util/state.ts
diff --git a/packages/tailwindcss-language-server/src/util/state.ts b/packages/tailwindcss-language-server/src/util/state.ts
index 4b258320520a2dc616f627a4d1e5f73ad3742383..175dade6ed563cc36605c1fc3c55f5b56e900573 100644
--- a/packages/tailwindcss-language-server/src/util/state.ts
+++ b/packages/tailwindcss-language-server/src/util/state.ts
@@ -28,19 +28,20 @@   emmetCompletions: boolean
 }
 
 export type State = null | {
-  config: any
-
 export type ClassNamesTree = {
-
   [key: string]: ClassNamesTree
-
+export type ClassNamesTree = {
 }
-
+export type ClassNamesTree = {
 export type ClassNamesContext = {
-
+export type ClassNamesTree = {
   [key: string]: string[]
-
+export type ClassNamesTree = {
 export type ClassNames = {
+  variants?: string[]
+  classNames?: ClassNames
+  dependencies?: string[]
+  editor?: EditorState
 }
 
 export type DocumentClassList = {