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
84
85
|
import {
TextDocument,
Diagnostic,
DiagnosticSeverity,
} from 'vscode-languageserver'
import { State } from '../util/state'
import { isCssDoc } from '../util/css'
import { findClassNamesInRange } from '../util/find'
import { getClassNameParts } from '../util/getClassNameAtPosition'
const dlv = require('dlv')
function provideCssDiagnostics(state: State, document: TextDocument): void {
const classNames = findClassNamesInRange(document, undefined, 'css')
let diagnostics: Diagnostic[] = classNames
.map(({ className, range }) => {
const parts = getClassNameParts(state, className)
if (!parts) return null
const info = dlv(state.classNames.classNames, parts)
let message: string
if (Array.isArray(info)) {
message = `\`@apply\` cannot be used with \`.${className}\` because it is included in multiple rulesets.`
} else if (info.__source !== 'utilities') {
message = `\`@apply\` cannot be used with \`.${className}\` because it is not a utility.`
} else if (info.__context && info.__context.length > 0) {
if (info.__context.length === 1) {
message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of an at-rule (${info.__context[0]}).`
} else {
message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of at-rules (${info.__context.join(
', '
)}).`
}
} else if (info.__pseudo && info.__pseudo.length > 0) {
if (info.__pseudo.length === 1) {
message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes a pseudo-selector (${info.__pseudo[0]})`
} else {
message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes pseudo-selectors (${info.__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)
}
}
|