tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Update `context.getClassList` usage (#707)
* Update `context.getClassList` usage
* fix default metadata
Signature
-----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJj06h/CRBK7hj4Ov3rIwAApdUIAHg4lF4sghLbMM5za1HdhpIt
P3W1hcNW8OHezK8A4qDVkk0m4n9uMrSBtGhZrN4r9XAruIdpHWP/kcmY+/4HS2i+
4lDJ0LQ/jp8XJBahHFYBrMJl23DkjGdz/XhECnH3YOQo5JyltzmvgjECq7XqeHuo
SGlo5rsNYvX410H4/O2XQHlSEskignDNk+D6nrzApYJHLv0WNK0m0etR4AlJAOia
6uPM4O2QsMk//agGEfnx3y2M+bXjQ+NP4tzbV4bjDLQC1481KiCxfnyYn++m/eJa
v5bQRZ/J5kI9n8DpDuisCQiXMRRZv6Wn2JUxFlb5AJeDQERgQEtZMelbdeAjOxs=
=8Ea4
-----END PGP SIGNATURE-----
diff --git a/packages/tailwindcss-language-server/src/server.ts b/packages/tailwindcss-language-server/src/server.ts
index 190503a8a44871df2191a3ffa9e36a2815cd5ee1..897acb5fba07da4a787f9fae79d68840b1e9cff1 100644
--- a/packages/tailwindcss-language-server/src/server.ts
+++ b/packages/tailwindcss-language-server/src/server.ts
@@ -1003,15 +1003,19 @@ if (state.jit) {
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
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 9f7a246cd3d96580cb705ca6551bac845ced5dd2..0ca4912421f22290fee572e99e5184bc34314bb8 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -75,15 +75,12 @@ ) {
// 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])
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index cba7c64faf85135984c3ac79d964f6392f05b40a..51677af8015d2f6bafe6c13ec207043c40c1284b 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -118,6 +118,7 @@ editor?: EditorState
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[] }