Skip to content
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
3 changes: 3 additions & 0 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ async function createProjectService(
.getClassList()
.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) }]
})
}
Expand Down
38 changes: 27 additions & 11 deletions packages/tailwindcss-language-service/src/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,43 @@ export function completionsFromClassList(
}

if (state.jit) {
let { variants: existingVariants, offset } = getVariantsFromClassName(state, partialClassName)

if (
context &&
(context.triggerKind === 1 ||
(context.triggerKind === 2 && context.triggerCharacter === '/')) &&
partialClassName.includes('/')
) {
// opacity modifiers
// modifiers
let modifiers: string[]
let beforeSlash = partialClassName.split('/').slice(0, -1).join('/')
let testClass = beforeSlash + '/[0]'
let { rules } = jit.generateRules(state, [testClass])
if (rules.length > 0) {
let opacities = dlv(state.config, 'theme.opacity', {})
if (!isObject(opacities)) {
opacities = {}
let classListContainsModifiers = state.classList.some(
(cls) => Array.isArray(cls) && cls[1].modifiers
)

if (classListContainsModifiers) {
let baseClassName = beforeSlash.slice(offset)
modifiers = state.classList.find(
(cls) => Array.isArray(cls) && cls[0] === baseClassName
)?.[1].modifiers
} else {
let testClass = beforeSlash + '/[0]'
let { rules } = jit.generateRules(state, [testClass])
if (rules.length > 0) {
let opacities = dlv(state.config, 'theme.opacity', {})
if (!isObject(opacities)) {
opacities = {}
}
modifiers = Object.keys(opacities)
}
}

if (modifiers) {
return {
isIncomplete: false,
items: Object.keys(opacities).map((opacity, index) => {
let className = `${beforeSlash}/${opacity}`
items: modifiers.map((modifier, index) => {
let className = `${beforeSlash}/${modifier}`
let kind: CompletionItemKind = 21
let documentation: string = null

Expand Down Expand Up @@ -110,8 +128,6 @@ export function completionsFromClassList(
}
}

let { variants: existingVariants, offset } = getVariantsFromClassName(state, partialClassName)

replacementRange.start.character += offset

let important = partialClassName.substr(offset).startsWith('!')
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-service/src/util/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export interface State {
editor?: EditorState
jit?: boolean
jitContext?: any
classList?: Array<[string, { color: culori.Color | KeywordColor | null }]>
classList?: Array<[string, { color: culori.Color | KeywordColor | null; modifiers?: string[] }]>
pluginVersions?: string
// postcssPlugins?: { before: any[]; after: any[] }
}
Expand Down