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
81
82
83
|
import {
TextDocument,
Diagnostic,
DiagnosticSeverity,
} from 'vscode-languageserver'
import { State } from '../util/state'
import { isCssDoc } from '../util/css'
import { findClassNamesInRange } from '../util/find'
import { getClassNameMeta } from '../util/getClassNameMeta'
function provideCssDiagnostics(state: State, document: TextDocument): void {
const classNames = findClassNamesInRange(document, undefined, 'css')
let diagnostics: Diagnostic[] = classNames
.map(({ className, range }) => {
const meta = getClassNameMeta(state, className)
if (!meta) return null
let message: string
if (Array.isArray(meta)) {
message = `\`@apply\` cannot be used with \`.${className}\` because it is included in multiple rulesets.`
} else if (meta.source !== 'utilities') {
message = `\`@apply\` cannot be used with \`.${className}\` because it is not a utility.`
} else if (meta.context && meta.context.length > 0) {
if (meta.context.length === 1) {
message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of an at-rule (${meta.context[0]}).`
} else {
message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of at-rules (${meta.context.join(
', '
)}).`
}
} else if (meta.pseudo && meta.pseudo.length > 0) {
if (meta.pseudo.length === 1) {
message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes a pseudo-selector (${meta.pseudo[0]})`
} else {
message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes pseudo-selectors (${meta.pseudo.join(
', '
)})`
}
}
if (!message) return null
return {
severity: DiagnosticSeverity.Error,
range,
message,
// source: 'ex',
}
})
.filter(Boolean)
// if (state.editor.capabilities.diagnosticRelatedInformation) {
// diagnostic.relatedInformation = [
// {
// location: {
// uri: document.uri,
// range: Object.assign({}, diagnostic.range),
// },
// message: '',
// },
// {
// location: {
// uri: document.uri,
// range: Object.assign({}, diagnostic.range),
// },
// message: '',
// },
// ]
// }
state.editor.connection.sendDiagnostics({ uri: document.uri, diagnostics })
}
export async function provideDiagnostics(
state: State,
document: TextDocument
): Promise<void> {
if (isCssDoc(state, document)) {
return provideCssDiagnostics(state, document)
}
}
|