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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 89cf8f4fba739c221c0c8d1ab5b3f4621368c60c..86bb582a19235ffbfac1b582443e006089dac38f 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -28,11 +28,14 @@ import { ensureArray } from './util/array'
import { getClassAttributeLexer, getComputedClassAttributeLexer } from './util/lexers'
import { validateApply } from './util/validateApply'
import { flagEnabled } from './util/flagEnabled'
-import { remToPx } from './util/remToPx'
import * as jit from './util/jit'
import { getVariantsFromClassName } from './util/getVariantsFromClassName'
import * as culori from 'culori'
import Regex from 'becke-ch--regex--s0-0-v1--base--pl--lib'
+import {
+ addPixelEquivalentsToMediaQuery,
+ addPixelEquivalentsToValue,
+} from './util/pixelEquivalents'
let isUtil = (className) =>
Array.isArray(className.__info)
@@ -43,6 +46,7 @@ export function completionsFromClassList(
state: State,
classList: string,
classListRange: Range,
+ rootFontSize: number,
filter?: (item: CompletionItem) => boolean,
context?: CompletionContext
): CompletionList {
@@ -190,7 +194,10 @@
items.push(
variantItem({
label: `${variant.name}${sep}`,
- detail: variant.selectors().join(', '),
+ detail: variant
+ .selectors()
+ .map((selector) => addPixelEquivalentsToMediaQuery(selector, rootFontSize))
+ .join(', '),
textEditText: resultingVariants[resultingVariants.length - 1] + sep,
additionalTextEdits:
shouldSortVariants && resultingVariants.length > 1
@@ -430,10 +437,9 @@ start: document.positionAt(Math.max(0, document.offsetAt(position) - 2000)),
end: position,
})
- let matches = matchClassAttributes(
- str,
- (await state.editor.getConfiguration(document.uri)).tailwindCSS.classAttributes
- )
+ let settings = (await state.editor.getConfiguration(document.uri)).tailwindCSS
+
+ let matches = matchClassAttributes(str, settings.classAttributes)
if (matches.length === 0) {
return null
@@ -470,6 +476,7 @@ character: position.character - classList.length,
},
end: position,
},
+ settings.rootFontSize,
undefined,
context
)
@@ -544,6 +551,7 @@ character: position.character - classList.length,
},
end: position,
},
+ settings.tailwindCSS.rootFontSize,
undefined,
context
)
@@ -555,12 +563,13 @@
return null
}
-function provideAtApplyCompletions(
+async function provideAtApplyCompletions(
state: State,
document: TextDocument,
position: Position,
context?: CompletionContext
-): CompletionList {
+): Promise<CompletionList> {
+ let settings = (await state.editor.getConfiguration(document.uri)).tailwindCSS
let str = document.getText({
start: { line: Math.max(position.line - 30, 0), character: 0 },
end: position,
@@ -584,6 +593,7 @@ character: position.character - classList.length,
},
end: position,
},
+ settings.rootFontSize,
(item) => {
if (item.kind === 9) {
return (
@@ -1318,13 +1328,18 @@
const parts = emmetItems.items[0].label.split('.')
if (parts.length < 2) return null
- return completionsFromClassList(state, parts[parts.length - 1], {
- start: {
- line: position.line,
- character: position.character - parts[parts.length - 1].length,
+ return completionsFromClassList(
+ state,
+ parts[parts.length - 1],
+ {
+ start: {
+ line: position.line,
+ character: position.character - parts[parts.length - 1].length,
+ },
+ end: position,
},
- end: position,
- })
+ settings.tailwindCSS.rootFontSize
+ )
}
export async function doComplete(
@@ -1444,10 +1459,10 @@ return props
.map((prop) =>
ensureArray(obj[prop])
.map((value) => {
- const px = settings.tailwindCSS.showPixelEquivalents
- ? remToPx(value, settings.tailwindCSS.rootFontSize)
- : undefined
- return `${prop}: ${value}${px ? `/* ${px} */` : ''};`
+ if (settings.tailwindCSS.showPixelEquivalents) {
+ value = addPixelEquivalentsToValue(value, settings.tailwindCSS.rootFontSize)
+ }
+ return `${prop}: ${value};`
})
.join(' ')
)
|