Skip to content

Commit c7f0ce2

Browse files
committed
wip
1 parent a54c8c5 commit c7f0ce2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

packages/tailwindcss-language-service/src/features/source-inline.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ export async function provideCodeLens(state: State, doc: TextDocument): Promise<
1919
maximumFractionDigits: 2,
2020
})
2121

22-
let byteFormatter = new Intl.NumberFormat('en', {
23-
notation: 'compact',
24-
style: 'unit',
25-
unit: 'byte',
26-
unitDisplay: 'narrow',
27-
})
28-
2922
let lenses: CodeLens[] = []
3023

3124
for (let match of findAll(PATTERN, text)) {
3225
let glob = match.groups.glob.slice(1, -1)
3326

3427
// Perform brace expansion
35-
let expanded = new Set(braces.expand(glob))
28+
let expanded = new Set<string>(braces.expand(glob))
3629
if (expanded.size < 2) continue
3730

3831
let slice: Range = absoluteRange({
@@ -57,7 +50,7 @@ export async function provideCodeLens(state: State, doc: TextDocument): Promise<
5750
lenses.push({
5851
range: slice,
5952
command: {
60-
title: `At least ${byteFormatter.format(size)} of CSS`,
53+
title: `At least ${formatBytes(size)} of CSS`,
6154
command: '',
6255
},
6356
})
@@ -90,7 +83,7 @@ function approximateByteSize(className: string) {
9083
// .class-name {
9184
// &:variant-1 {
9285
// &:variant-2 {
93-
// /* properties */
86+
//
9487
// }
9588
// }
9689
// }
@@ -105,8 +98,17 @@ function approximateByteSize(className: string) {
10598
size += (depth + 1) * 2 + 2
10699
}
107100

108-
// Properties comment
109-
size += 16
101+
// ~1.95x is a rough growth factor due to the actual properties being present
102+
return size * 1.95
103+
}
110104

111-
return size
105+
const UNITS = ['byte', 'kilobyte', 'megabyte', 'gigabyte', 'terabyte', 'petabyte']
106+
function formatBytes(n: number) {
107+
let i = n == 0 ? 0 : Math.floor(Math.log(n) / Math.log(1000))
108+
return new Intl.NumberFormat('en', {
109+
notation: 'compact',
110+
style: 'unit',
111+
unit: UNITS[i],
112+
unitDisplay: 'narrow',
113+
}).format(n / 1000 ** i)
112114
}

0 commit comments

Comments
 (0)