Skip to content

Update context.getClassList usage #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,15 +989,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions packages/tailwindcss-language-service/src/util/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface State {
jit?: boolean
jitContext?: any
classList?: Array<[string, { color: culori.Color | KeywordColor | null; modifiers?: string[] }]>
classListContainsMetadata?: boolean
pluginVersions?: string
// postcssPlugins?: { before: any[]; after: any[] }
}
Expand Down