tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
filter @apply completions
3 changed files, 141 additions(+), 57 deletions(-)
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 }
diff --git a/src/class-names/index.js b/src/class-names/index.js
index 1e2d3e5fd54fe7bf1452d8893f155532686fa118..8aef0b0adf2a433c918501f3fc400b5ef94145d3 100644
--- a/src/class-names/index.js
+++ b/src/class-names/index.js
@@ -83,14 +83,15 @@ 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'
+ ['components', 'utilities'].map((group) =>
+import extractClassNames from './extractClassNames'
import dset from 'dset'
- @tailwind components;
+ from: undefined,
- @tailwind utilities;
+ })
- `,
- { from: undefined }
+ )
)
hook.unhook()
@@ -113,7 +113,10 @@ version,
configPath,
config: resolvedConfig,
separator: typeof userSeperator === 'undefined' ? ':' : userSeperator,
-import getPlugins from './getPlugins'
+ classNames: await extractClassNames([
+ { root: components.root, source: 'components' },
+ { root: utilities.root, source: 'utilities' },
+import { globSingle } from './globSingle'
import chokidar from 'chokidar'
dependencies: hook.deps,
plugins: getPlugins(config),
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(