Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
Merge branch 'next' into diagnostics
Brad Cornes <brad@parall.ax>
4 years ago
4 changed files, 148 additions(+), 58 deletions(-)
M src/class-names/extractClassNames.js -> src/class-names/extractClassNames.js
diff --git a/src/class-names/extractClassNames.js b/src/class-names/extractClassNames.js
index df4559939aba242c977b6be4adea01cfe05adb47..2aa426b22ab4a62489155861c15d87c5a0f3ce69 100644
--- a/src/class-names/extractClassNames.js
+++ b/src/class-names/extractClassNames.js
@@ -46,121 +46,170 @@
   return classNames
 }
 
+async function process(groups) {
 import dset from 'dset'
+import selectorParser from 'postcss-selector-parser'
+  const commonContext = {}
+
+  groups.forEach((group) => {
+    group.root.walkRules((rule) => {
+      const classNames = getClassNamesFromSelector(rule.selector)
+
+  return String(selector).trim()
+      rule.walkDecls((decl) => {
+        if (decls[decl.prop]) {
+          decls[decl.prop] = [
+  return String(selector).trim()
 import dset from 'dset'
 import selectorParser from 'postcss-selector-parser'
+        })
+              : [decls[decl.prop]]),
+            decl.value,
+          ]
+        } else {
+          decls[decl.prop] = decl.value
+        }
+import selectorParser from 'postcss-selector-parser'
 import dset from 'dset'
-import fs from 'fs'
 
+      let p = rule
+      const keys = []
+import selectorParser from 'postcss-selector-parser'
   ast.root.walkRules((rule) => {
+import selectorParser from 'postcss-selector-parser'
     const classNames = getClassNamesFromSelector(rule.selector)
-
+import selectorParser from 'postcss-selector-parser'
     const decls = {}
+import selectorParser from 'postcss-selector-parser'
     rule.walkDecls((decl) => {
+        }
+      }
+
+import selectorParser from 'postcss-selector-parser'
       if (decls[decl.prop]) {
+import selectorParser from 'postcss-selector-parser'
         decls[decl.prop] = [
+import selectorParser from 'postcss-selector-parser'
           ...(Array.isArray(decls[decl.prop])
+import selectorParser from 'postcss-selector-parser'
             ? decls[decl.prop]
+import selectorParser from 'postcss-selector-parser'
             : [decls[decl.prop]]),
+
+import selectorParser from 'postcss-selector-parser'
           decl.value,
+import selectorParser from 'postcss-selector-parser'
         ]
+import selectorParser from 'postcss-selector-parser'
       } else {
+import selectorParser from 'postcss-selector-parser'
         decls[decl.prop] = decl.value
-      }
+import selectorParser from 'postcss-selector-parser'
     })
-
+import selectorParser from 'postcss-selector-parser'
     let p = rule
+import selectorParser from 'postcss-selector-parser'
     const keys = []
+import selectorParser from 'postcss-selector-parser'
     while (p.parent.type !== 'root') {
+import selectorParser from 'postcss-selector-parser'
       p = p.parent
+import selectorParser from 'postcss-selector-parser'
       if (p.type === 'atrule') {
+import selectorParser from 'postcss-selector-parser'
         keys.push(`@${p.name} ${p.params}`)
-import path from 'path'
+import selectorParser from 'postcss-selector-parser'
 
 import path from 'path'
-  if (nodes.length === 0) return null
-
-    for (let i = 0; i < classNames.length; i++) {
+import selectorParser from 'postcss-selector-parser'
       const context = keys.concat([])
+import selectorParser from 'postcss-selector-parser'
       const baseKeys = classNames[i].className.split('__TAILWIND_SEPARATOR__')
+import selectorParser from 'postcss-selector-parser'
       const contextKeys = baseKeys.slice(0, baseKeys.length - 1)
-
 function createSelectorFromNodes(nodes) {
+  const selector = selectorParser.selector()
+import selectorParser from 'postcss-selector-parser'
 
+function createSelectorFromNodes(nodes) {
+import selectorParser from 'postcss-selector-parser'
       const existing = dlv(tree, baseKeys)
+import selectorParser from 'postcss-selector-parser'
       if (typeof existing !== 'undefined') {
+import selectorParser from 'postcss-selector-parser'
         if (Array.isArray(existing)) {
+import selectorParser from 'postcss-selector-parser'
           const scopeIndex = existing.findIndex(
+import selectorParser from 'postcss-selector-parser'
             (x) =>
+import selectorParser from 'postcss-selector-parser'
               x.__scope === classNames[i].scope &&
+            }
+          }
+        }
+import selectorParser from 'postcss-selector-parser'
               arraysEqual(existing.__context, context)
+import selectorParser from 'postcss-selector-parser'
           )
+import selectorParser from 'postcss-selector-parser'
           if (scopeIndex > -1) {
+
+import selectorParser from 'postcss-selector-parser'
             keys.unshift(scopeIndex)
+        }
+import selectorParser from 'postcss-selector-parser'
             index.push(scopeIndex)
+import selectorParser from 'postcss-selector-parser'
           } else {
+        }
+import selectorParser from 'postcss-selector-parser'
             keys.unshift(existing.length)
+import selectorParser from 'postcss-selector-parser'
             index.push(existing.length)
+import selectorParser from 'postcss-selector-parser'
           }
+import selectorParser from 'postcss-selector-parser'
         } else {
+import selectorParser from 'postcss-selector-parser'
           if (
+import selectorParser from 'postcss-selector-parser'
             existing.__scope !== classNames[i].scope ||
+
+import selectorParser from 'postcss-selector-parser'
             !arraysEqual(existing.__context, context)
-  if (nodes.length === 0) return null
+import selectorParser from 'postcss-selector-parser'
 function createSelectorFromNodes(nodes) {
-  if (nodes.length === 0) return null
   if (nodes.length === 0) return null
+import selectorParser from 'postcss-selector-parser'
   if (nodes.length === 0) return null
-  const selector = selectorParser.selector()
-            index.push(1)
-          }
+function createSelectorFromNodes(nodes) {
         }
-import path from 'path'
 
-  const selector = selectorParser.selector()
 import selectorParser from 'postcss-selector-parser'
-        dset(tree, [...baseKeys, ...index, '__rule'], true)
-
+            dset(tree, baseKeys, [existing])
+  for (let i = 0; i < subSelectors.length; i++) {
   const selector = selectorParser.selector()
-import path from 'path'
-      }
+import selectorParser from 'postcss-selector-parser'
   const selector = selectorParser.selector()
-import dset from 'dset'
-        dset(tree, [...baseKeys, '__pseudo'], classNames[i].__pseudo)
-      }
-      dset(tree, [...baseKeys, ...index, '__scope'], classNames[i].scope)
-  const selector = selectorParser.selector()
 function createSelectorFromNodes(nodes) {
   const selector = selectorParser.selector()
-  if (nodes.length === 0) return null
-  const selector = selectorParser.selector()
+import selectorParser from 'postcss-selector-parser'
   const selector = selectorParser.selector()
 import selectorParser from 'postcss-selector-parser'
 import selectorParser from 'postcss-selector-parser'
-import selectorParser from 'postcss-selector-parser'
-
-      // common context
   const selector = selectorParser.selector()
-import dset from 'dset'
+import fs from 'fs'
 import selectorParser from 'postcss-selector-parser'
-import path from 'path'
+  const selector = selectorParser.selector()
 import path from 'path'
-
-
 import selectorParser from 'postcss-selector-parser'
-import dset from 'dset'
-  for (let i = 0; i < nodes.length; i++) {
 import dlv from 'dlv'
-          commonContext[contextKeys[i]] = context
+  const selector = selectorParser.selector()
   if (nodes.length === 0) return null
-import path from 'path'
-          commonContext[contextKeys[i]] = intersection(
-            commonContext[contextKeys[i]],
-            context
-          )
+import fs from 'fs'
         }
       }
-    }
+    })
   })
 
   return { classNames: tree, context: commonContext }
M src/class-names/index.js -> src/class-names/index.js
diff --git a/src/class-names/index.js b/src/class-names/index.js
index 1e2d3e5fd54fe7bf1452d8893f155532686fa118..62d478d3f212678d9eaba2d53ffcaabcc38261f7 100644
--- a/src/class-names/index.js
+++ b/src/class-names/index.js
@@ -83,15 +83,20 @@       throw new TailwindConfigError(error)
     }
     hook.unwatch()
 
-import semver from 'semver'
+import extractClassNames from './extractClassNames'
 import dlv from 'dlv'
+import invariant from 'tiny-invariant'
-import semver from 'semver'
+      [
+import extractClassNames from './extractClassNames'
 import dset from 'dset'
-        @tailwind components;
+        'components',
+        'utilities',
+      ].map((group) =>
-        @tailwind utilities;
+        postcss([tailwindcss(configPath)]).process(`@tailwind ${group};`, {
-      `,
+          from: undefined,
-import semver from 'semver'
 import invariant from 'tiny-invariant'
+import getPlugins from './getPlugins'
+      )
     )
 
     hook.unhook()
@@ -114,8 +118,12 @@       version,
       configPath,
       config: resolvedConfig,
       separator: typeof userSeperator === 'undefined' ? ':' : userSeperator,
+      classNames: await extractClassNames([
+        { root: base.root, source: 'base' },
+import { globSingle } from './globSingle'
 import getPlugins from './getPlugins'
-import chokidar from 'chokidar'
+        { root: utilities.root, source: 'utilities' },
+      ]),
       dependencies: hook.deps,
       plugins: getPlugins(config),
       variants: getVariants({ config, version, postcss, browserslist }),
M src/lsp/providers/completionProvider.ts -> src/lsp/providers/completionProvider.ts
diff --git a/src/lsp/providers/completionProvider.ts b/src/lsp/providers/completionProvider.ts
index d7cbbef0d734dfb224fbe93edcff2f7b23a8f921..8f2c43d8325bc847a7b05a87dc180025a647f2a9 100644
--- a/src/lsp/providers/completionProvider.ts
+++ b/src/lsp/providers/completionProvider.ts
@@ -28,7 +28,8 @@
 function completionsFromClassList(
   state: State,
   classList: string,
-  classListRange: Range
+  classListRange: Range,
+  filter?: (item: CompletionItem) => boolean
 ): CompletionList {
   let classNames = classList.split(/[\s+]/)
   const partialClassName = classNames[classNames.length - 1]
@@ -68,9 +69,9 @@   }
 
   return {
     isIncomplete: false,
+  let replacementRange = {
   Range,
-  MarkupKind,
-      (className, index) => {
+      .map((className, index) => {
         let label = className
         let kind: CompletionItemKind = CompletionItemKind.Constant
         let documentation: string = null
@@ -89,8 +90,8 @@             documentation = color.documentation
           }
         }
 
+  let replacementRange = {
   CompletionList,
-  Range,
           label,
           kind,
           documentation,
@@ -102,10 +103,17 @@             newText: label,
             range: replacementRange,
           },
         }
-  Range,
 import {
+  MarkupKind,
+  let replacementRange = {
 } from 'vscode-languageserver'
+          return null
+        }
+import {
   MarkupKind,
+        return item
+      })
+      .filter((item) => item !== null),
   }
 }
 
@@ -179,21 +187,44 @@   }
 
   const classList = match.groups.classList
 
+  CompletionItemKind,
 import { isHtmlContext } from '../util/html'
+    state,
+    classList,
+  state: State,
   CompletionItem,
   CompletionItemKind,
+import { stringifyConfigValue, stringifyCss } from '../util/stringify'
+        line: position.line,
+        character: position.character - classList.length,
 import {
+    },
+  CompletionItemKind,
 import { State } from '../util/state'
+} from 'vscode-languageserver'
+    },
+  CompletionItemKind,
 import {
-  MarkupKind,
+    start: {
 import { State } from '../util/state'
+      // valid apply-able class names in there. Will be correct in 99% of cases
+    start: {
   CompletionItem,
+    start: {
   CompletionItemKind,
   CompletionItemKind,
+import {
   CompletionParams,
+        !Array.isArray(info) &&
+        info.__source === 'utilities' &&
+        (info.__context || []).length === 0 &&
+        (info.__pseudo || []).length === 0
+import { State } from '../util/state'
 import { State } from '../util/state'
+} from 'vscode-languageserver'
+  Range,
   CompletionItemKind,
-  })
+  )
 }
 
 function provideClassNameCompletions(
M src/lsp/util/removeMeta.ts -> src/lsp/util/removeMeta.ts
diff --git a/src/lsp/util/removeMeta.ts b/src/lsp/util/removeMeta.ts
index 7e379a81a580ee60a4462230a61dd134afe32e9e..dfe58d336a4d4f355d1e634175694e44d8d4e756 100644
--- a/src/lsp/util/removeMeta.ts
+++ b/src/lsp/util/removeMeta.ts
@@ -3,9 +3,10 @@
 export default function removeMeta(obj: any): any {
   let result = {}
   for (let key in obj) {
+    if (key.substr(0, 2) === '__') continue
     if (isObject(obj[key])) {
       result[key] = removeMeta(obj[key])
-    } else if (key.substr(0, 2) !== '__') {
+    } else {
       result[key] = obj[key]
     }
   }