Update `context.getClassList` usage (#707)

* Update `context.getClassList` usage

* fix default metadata
master
Brad Cornes 2023-01-27 10:33:35 +00:00 committed by GitHub
parent 637f838725
commit 0fab387f77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -1003,15 +1003,19 @@ async function createProjectService(
state.jitContext = state.modules.jit.createContext.module(state)
state.jitContext.tailwindConfig.separator = state.config.separator
if (state.jitContext.getClassList) {
state.classList = state.jitContext
.getClassList()
let classList = state.jitContext
.getClassList({ includeMetadata: true })
.filter((className) => className !== '*')
.map((className) => {
if (Array.isArray(className)) {
return [className[0], { color: getColor(state, className[0]), ...className[1] }]
}
return [className, { color: getColor(state, className) }]
})
state.classListContainsMetadata = classList.some((cls) => Array.isArray(cls))
state.classList = classList.map((className) => {
if (Array.isArray(className)) {
return [
className[0],
{ color: getColor(state, className[0]), ...(className[1] ?? {}) },
]
}
return [className, { color: getColor(state, className) }]
})
}
} else {
delete state.jitContext

View File

@ -75,15 +75,12 @@ export function completionsFromClassList(
// modifiers
let modifiers: string[]
let beforeSlash = partialClassName.split('/').slice(0, -1).join('/')
let classListContainsModifiers = state.classList.some(
(cls) => Array.isArray(cls) && cls[1].modifiers
)
if (classListContainsModifiers) {
if (state.classListContainsMetadata) {
let baseClassName = beforeSlash.slice(offset)
modifiers = state.classList.find(
(cls) => Array.isArray(cls) && cls[0] === baseClassName
)?.[1].modifiers
)?.[1]?.modifiers
} else {
let testClass = beforeSlash + '/[0]'
let { rules } = jit.generateRules(state, [testClass])

View File

@ -118,6 +118,7 @@ export interface State {
jit?: boolean
jitContext?: any
classList?: Array<[string, { color: culori.Color | KeywordColor | null; modifiers?: string[] }]>
classListContainsMetadata?: boolean
pluginVersions?: string
completionItemData?: Record<string, any>
// postcssPlugins?: { before: any[]; after: any[] }