@@ -19,20 +19,13 @@ export async function provideCodeLens(state: State, doc: TextDocument): Promise<
19
19
maximumFractionDigits : 2 ,
20
20
} )
21
21
22
- let byteFormatter = new Intl . NumberFormat ( 'en' , {
23
- notation : 'compact' ,
24
- style : 'unit' ,
25
- unit : 'byte' ,
26
- unitDisplay : 'narrow' ,
27
- } )
28
-
29
22
let lenses : CodeLens [ ] = [ ]
30
23
31
24
for ( let match of findAll ( PATTERN , text ) ) {
32
25
let glob = match . groups . glob . slice ( 1 , - 1 )
33
26
34
27
// Perform brace expansion
35
- let expanded = new Set ( braces . expand ( glob ) )
28
+ let expanded = new Set < string > ( braces . expand ( glob ) )
36
29
if ( expanded . size < 2 ) continue
37
30
38
31
let slice : Range = absoluteRange ( {
@@ -57,7 +50,7 @@ export async function provideCodeLens(state: State, doc: TextDocument): Promise<
57
50
lenses . push ( {
58
51
range : slice ,
59
52
command : {
60
- title : `At least ${ byteFormatter . format ( size ) } of CSS` ,
53
+ title : `At least ${ formatBytes ( size ) } of CSS` ,
61
54
command : '' ,
62
55
} ,
63
56
} )
@@ -90,7 +83,7 @@ function approximateByteSize(className: string) {
90
83
// .class-name {
91
84
// &:variant-1 {
92
85
// &:variant-2 {
93
- // /* properties */
86
+ // …
94
87
// }
95
88
// }
96
89
// }
@@ -105,8 +98,17 @@ function approximateByteSize(className: string) {
105
98
size += ( depth + 1 ) * 2 + 2
106
99
}
107
100
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
+ }
110
104
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 )
112
114
}
0 commit comments