tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
Support class modifiers (#686)
Signature
-----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJjtFY3CRBK7hj4Ov3rIwAA2WkIADzPZTofVZR2TpSpuls1jJWB
cTwj5egwaMlR9Pjp2aY+h+Yh4tJ03QbvVxLv1C0mHQzsLk+7M2X4HWwgIHuFKdps
4/TlSNxuSfwz4vom0M/Bl+wxbY6xNQAy6QmprBtIJX5KK4CoMrj1mY6ISw0yMMdE
c5g71s/TCpA4uCVLcq04md5Z2LyNEf6+NRvsXMVE5fmPG2gKiuQvXBUgyTB4hKFH
jSpmjbz0/QHs6z4lHxJvtwtYHCKG/VZAQtoCa8D0W4WNJyoRhkoM6E4QaUMUKxeI
iotkNtxPewkNPsHBx0OhnA+3zMx0xALMHrvHh1ZpBN1W41lmfvGmrnDhG039aTU=
=2Im8
-----END PGP SIGNATURE-----
3 changed files, 31 additions(+), 12 deletions(-)
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index 980b5d99e423c790ae1edf14628afa45e55a45b5..34372980b5cad811be63d94806235d1e4ad7f506 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -991,6 +991,9 @@ state.classList = state.jitContext
.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) }]
})
}
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 2ee4871784f9b4eecb646ed1ea86a5cc4d0ec8ee..d8bee18835f75d8e646c3d7742b7c0e79c6f047f 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -64,25 +64,43 @@ },
}
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
@@ -109,8 +127,6 @@ }),
}
}
}
-
- let { variants: existingVariants, offset } = getVariantsFromClassName(state, partialClassName)
replacementRange.start.character += offset
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index 5d5c8321727efd11d0426c3d3eca1678def9318f..3787bdcfa6213f187e9fdd458f83791ab7a34e9b 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -116,7 +116,7 @@ classNames?: ClassNames
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[] }
}