@@ -2,7 +2,7 @@ import { findClassNamesInRange } from '../../util/find'
2
2
import { InvalidApplyDiagnostic , DiagnosticKind } from './types'
3
3
import { Settings , State } from '../../util/state'
4
4
import { TextDocument , DiagnosticSeverity } from 'vscode-languageserver'
5
- import { getClassNameMeta } from '../../util/getClassNameMeta '
5
+ import { validateApply } from '../../util/validateApply '
6
6
7
7
export function getInvalidApplyDiagnostics (
8
8
state : State ,
@@ -15,47 +15,20 @@ export function getInvalidApplyDiagnostics(
15
15
const classNames = findClassNamesInRange ( document , undefined , 'css' )
16
16
17
17
let diagnostics : InvalidApplyDiagnostic [ ] = classNames . map ( ( className ) => {
18
- const meta = getClassNameMeta ( state , className . className )
19
- if ( ! meta ) return null
18
+ let result = validateApply ( state , className . className )
20
19
21
- let message : string
22
-
23
- if ( Array . isArray ( meta ) ) {
24
- message = `'@apply' cannot be used with '${ className . className } ' because it is included in multiple rulesets.`
25
- } else if ( meta . source !== 'utilities' ) {
26
- message = `'@apply' cannot be used with '${ className . className } ' because it is not a utility.`
27
- } else if ( meta . context && meta . context . length > 0 ) {
28
- if ( meta . context . length === 1 ) {
29
- message = `'@apply' cannot be used with '${ className . className } ' because it is nested inside of an at-rule ('${ meta . context [ 0 ] } ').`
30
- } else {
31
- message = `'@apply' cannot be used with '${
32
- className . className
33
- } ' because it is nested inside of at-rules (${ meta . context
34
- . map ( ( c ) => `'${ c } '` )
35
- . join ( ', ' ) } ).`
36
- }
37
- } else if ( meta . pseudo && meta . pseudo . length > 0 ) {
38
- if ( meta . pseudo . length === 1 ) {
39
- message = `'@apply' cannot be used with '${ className . className } ' because its definition includes a pseudo-selector ('${ meta . pseudo [ 0 ] } ')`
40
- } else {
41
- message = `'@apply' cannot be used with '${
42
- className . className
43
- } ' because its definition includes pseudo-selectors (${ meta . pseudo
44
- . map ( ( p ) => `'${ p } '` )
45
- . join ( ', ' ) } ).`
46
- }
20
+ if ( result === null || result . isApplyable === true ) {
21
+ return null
47
22
}
48
23
49
- if ( ! message ) return null
50
-
51
24
return {
52
25
code : DiagnosticKind . InvalidApply ,
53
26
severity :
54
27
severity === 'error'
55
28
? DiagnosticSeverity . Error
56
29
: DiagnosticSeverity . Warning ,
57
30
range : className . range ,
58
- message,
31
+ message : result . reason ,
59
32
className,
60
33
}
61
34
} )
0 commit comments