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
|
diff --git a/src/lsp/providers/codeActionProvider/index.ts b/src/lsp/providers/codeActionProvider/index.ts
index 62bdb128c3e49cf2cd5895a14dff8cfa7064aef1..22298dad00a8abe4bea08c7a41651849e6c5e6dd 100644
--- a/src/lsp/providers/codeActionProvider/index.ts
+++ b/src/lsp/providers/codeActionProvider/index.ts
@@ -111,22 +111,18 @@ }
function classNameToAst(
state: State,
- className: string,
- selector: string = `.${className}`,
+ classNameParts: string[],
+ selector: string,
important: boolean = false
) {
- const parts = getClassNameParts(state, className)
- if (!parts) {
- return null
- }
const baseClassName = dlv(
state.classNames.classNames,
- parts[parts.length - 1]
+ classNameParts[classNameParts.length - 1]
)
if (!baseClassName) {
return null
}
- const info = dlv(state.classNames.classNames, parts)
+ const info = dlv(state.classNames.classNames, classNameParts)
let context = info.__context || []
let pseudo = info.__pseudo || []
const globalContexts = state.classNames.context
@@ -139,8 +135,8 @@ if (!isObject(screens)) screens = {}
screens = Object.keys(screens)
const path = []
- for (let i = 0; i < parts.length - 1; i++) {
- let part = parts[i]
+ for (let i = 0; i < classNameParts.length - 1; i++) {
+ let part = classNameParts[i]
let common = globalContexts[part]
if (!common) return null
if (screens.includes(part)) {
@@ -158,7 +154,7 @@ }
let rule = {
// TODO: use proper selector parser
[selector + pseudo.join('')]: {
- [`@apply ${parts[parts.length - 1]}${
+ [`@apply ${classNameParts[classNameParts.length - 1]}${
important ? ' !important' : ''
}`]: '',
},
@@ -221,6 +217,14 @@ let totalClassNamesInClassList = diagnostic.className.classList.classList.split(
/\s+/
).length
+ let className = diagnostic.className.className
+ let classNameParts = getClassNameParts(state, className)
+ let classNameInfo = dlv(state.classNames.classNames, classNameParts)
+
+ if (Array.isArray(classNameInfo)) {
+ return []
+ }
+
if (!isCssDoc(state, document)) {
let languageBoundaries = getLanguageBoundaries(state, document)
if (!languageBoundaries) return []
@@ -259,10 +263,9 @@ // keep looking
return true
}
- let className = diagnostic.className.className
let ast = classNameToAst(
state,
- className,
+ classNameParts,
rule.selector,
diagnostic.className.classList.important
)
|