1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index 9602ee720a1b61c82afe91012a516b17ce9374a5..ccb74ac3679f2b12d75004c46c408c28d4ecb923 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -9,13 +9,16 @@ import {
findClassNamesInRange,
findClassListsInDocument,
getClassNamesInClassList,
+ findAll,
+ indexToPosition,
} from '../util/find'
import { getClassNameMeta } from '../util/getClassNameMeta'
import { getClassNameDecls } from '../util/getClassNameDecls'
import { equal } from '../../util/array'
import { getDocumentSettings } from '../util/getDocumentSettings'
+const dlv = require('dlv')
-function getCssDiagnostics(
+function getUnsupportedApplyDiagnostics(
state: State,
document: TextDocument,
settings: Settings
@@ -128,6 +131,45 @@
return diagnostics
}
+function getScreenDirectiveDiagnostics(
+ state: State,
+ document: TextDocument,
+ settings: Settings
+): Diagnostic[] {
+ let severity = settings.lint.unknownScreen
+ if (severity === 'ignore') return []
+
+ let text = document.getText()
+ let matches = findAll(/(?:\s|^)@screen\s+(?<screen>[^\s{]+)/g, text)
+
+ let screens = Object.keys(
+ dlv(state.config, 'theme.screens', dlv(state.config, 'screens', {}))
+ )
+
+ return matches
+ .map((match) => {
+ if (screens.includes(match.groups.screen)) {
+ return null
+ }
+
+ return {
+ range: {
+ start: indexToPosition(
+ text,
+ match.index + match[0].length - match.groups.screen.length
+ ),
+ end: indexToPosition(text, match.index + match[0].length),
+ },
+ severity:
+ severity === 'error'
+ ? DiagnosticSeverity.Error
+ : DiagnosticSeverity.Warning,
+ message: 'Unknown screen',
+ }
+ })
+ .filter(Boolean)
+}
+
export async function provideDiagnostics(
state: State,
document: TextDocument
@@ -138,7 +180,10 @@ const diagnostics: Diagnostic[] = settings.validate
? [
...getUtilityConflictDiagnostics(state, document, settings),
...(isCssDoc(state, document)
- ? getCssDiagnostics(state, document, settings)
+ ? [
+ ...getUnsupportedApplyDiagnostics(state, document, settings),
+ ...getScreenDirectiveDiagnostics(state, document, settings),
+ ]
: []),
]
: []
|