Skip to content

Commit 0e4fb16

Browse files
committed
feat: refactor isClassValid function to improve invalid class checks
1 parent a5b9836 commit 0e4fb16

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

packages/tailwindcss-language-service/src/diagnostics/getInvalidClassDiagnostics.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,36 @@ import type { State, Settings, DocumentClassName } from '../util/state'
22
import { type InvalidClassDiagnostic, DiagnosticKind } from './types'
33
import { findClassListsInDocument, getClassNamesInClassList } from '../util/find'
44
import { visit } from './getCssConflictDiagnostics'
5+
import { getClassNameDecls } from '../util/getClassNameDecls'
6+
import * as jit from '../util/jit'
57
import type { TextDocument } from 'vscode-languageserver-textdocument'
68

79
function isClassValid(state: State, className: string): boolean {
8-
if (!state.v4) return true // Only check for v4
10+
if (state.v4) {
11+
// V4: Use design system compilation
12+
let roots = state.designSystem.compile([className])
13+
let hasDeclarations = false
914

10-
let roots = state.designSystem.compile([className])
11-
let hasDeclarations = false
12-
13-
visit([roots[0]], (node) => {
14-
if ((node.type === 'rule' || node.type === 'atrule') && node.nodes) {
15-
for (let child of node.nodes) {
16-
if (child.type === 'decl') {
17-
hasDeclarations = true
18-
break
15+
visit([roots[0]], (node) => {
16+
if ((node.type === 'rule' || node.type === 'atrule') && node.nodes) {
17+
for (let child of node.nodes) {
18+
if (child.type === 'decl') {
19+
hasDeclarations = true
20+
break
21+
}
1922
}
2023
}
21-
}
22-
})
23-
24-
return hasDeclarations
24+
})
25+
return hasDeclarations
26+
} else if (state.jit) {
27+
// JIT: Try to generate rules
28+
let { rules } = jit.generateRules(state, [className])
29+
return rules.length > 0
30+
} else {
31+
// Static: Check if decls exist
32+
let decls = getClassNameDecls(state, className)
33+
return !!decls
34+
}
2535
}
2636

2737
export async function getInvalidClassDiagnostics(

0 commit comments

Comments
 (0)