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
|
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 0cdff6335af81f60c4e76a8d6a187c71a1d6fa36..1a7165b95b5bd11fcff1ed4c28733673a3b18fbd 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -32,6 +32,7 @@ } from './util/lexers'
import { validateApply } from './util/validateApply'
import { flagEnabled } from './util/flagEnabled'
import MultiRegexp from 'multi-regexp2'
+import { remToPx } from './util/remToPx'
export function completionsFromClassList(
state: State,
@@ -876,10 +877,13 @@ item.detail = state.classNames.context[
item.data[item.data.length - 1]
].join(', ')
} else {
- item.detail = getCssDetail(state, className)
+ item.detail = await getCssDetail(state, className)
if (!item.documentation) {
- const { tabSize } = await getDocumentSettings(state)
- const css = stringifyCss(item.data.join(':'), className, tabSize)
+ const settings = await getDocumentSettings(state)
+ const css = stringifyCss(item.data.join(':'), className, {
+ tabSize: dlv(settings, 'tabSize'),
+ showPixelValues: dlv(settings, 'experimental.showPixelValues'),
+ })
if (css) {
item.documentation = {
kind: 'markdown' as typeof MarkupKind.Markdown,
@@ -907,7 +911,10 @@
return isObject(item.__info) && !item.__info.__rule
}
-function stringifyDecls(obj: any): string {
+function stringifyDecls(
+ obj: any,
+ { showPixelValues = false }: Partial<{ showPixelValues: boolean }> = {}
+): string {
let props = Object.keys(obj)
let nonCustomProps = props.filter((prop) => !prop.startsWith('--'))
@@ -918,18 +925,24 @@
return props
.map((prop) =>
ensureArray(obj[prop])
- .map((value) => `${prop}: ${value};`)
+ .map((value) => {
+ const px = showPixelValues ? remToPx(value) : undefined
+ return `${prop}: ${value}${px ? ` /*${px}*/` : ''};`
+ })
.join(' ')
)
.join(' ')
}
-function getCssDetail(state: State, className: any): string {
+async function getCssDetail(state: State, className: any): Promise<string> {
if (Array.isArray(className)) {
return `${className.length} rules`
}
if (className.__rule === true) {
- return stringifyDecls(removeMeta(className))
+ const settings = await getDocumentSettings(state)
+ return stringifyDecls(removeMeta(className), {
+ showPixelValues: dlv(settings, 'experimental.showPixelValues', false),
+ })
}
return null
}
|