@@ -28,14 +28,16 @@ object Profile:
28
28
29
29
inline val TastyChunkSize = 50
30
30
31
+ def chunks (size : Int ) = (size + TastyChunkSize - 1 ) / TastyChunkSize
32
+
31
33
case class MethodInfo (meth : Symbol , size : Int , span : Span )
32
34
@ sharable object NoInfo extends MethodInfo (NoSymbol , 0 , NoSpan )
33
35
34
36
class Info (details : Int ):
35
37
var lineCount : Int = 0
36
38
var tokenCount : Int = 0
37
39
var tastySize : Int = 0
38
- def complexity : Float = (tastySize/ TastyChunkSize ).toFloat/ lineCount
40
+ def complexity : Float = chunks (tastySize).toFloat/ lineCount
39
41
val leading : Array [MethodInfo ] = Array .fill[MethodInfo ](details)(NoInfo )
40
42
41
43
def recordMethodSize (meth : Symbol , size : Int , span : Span ): Unit =
@@ -56,7 +58,7 @@ class ActiveProfile(details: Int) extends Profile:
56
58
57
59
private def curInfo (using Context ): Profile .Info =
58
60
val unit : CompilationUnit | Null = ctx.compilationUnit
59
- if unit == null then junkInfo else unitProfile(unit)
61
+ if unit == null || unit.source.file.isVirtual then junkInfo else unitProfile(unit)
60
62
61
63
def unitProfile (unit : CompilationUnit ): Profile .Info =
62
64
pinfo.getOrElseUpdate(unit, new Profile .Info (details))
@@ -98,7 +100,7 @@ class ActiveProfile(details: Int) extends Profile:
98
100
else if complexity < 25 then " high "
99
101
else " extreme "
100
102
report.echo(layout.format(
101
- name, info.lineCount, info.tokenCount, info.tastySize/ Profile . TastyChunkSize ,
103
+ name, info.lineCount, info.tokenCount, Profile .chunks( info.tastySize) ,
102
104
s " ${" %6.2f" .format(complexity)} $explanation" , path))
103
105
104
106
def safeMax (xs : Array [Int ]) = xs.max.max(10 ).min(50 )
@@ -135,6 +137,7 @@ class ActiveProfile(details: Int) extends Profile:
135
137
val s = Scanner (meth.source, span.start, methProfile)(using methCtx)
136
138
while s.offset < span.end do s.nextToken()
137
139
val info = methProfile.unitProfile(unit)
140
+ info.lineCount += 1
138
141
info.tastySize = size
139
142
val file = meth.source.file
140
143
val header = s " %- ${sourceNameWidth}s %- ${methNameWidth}s " .format(file.name, meth.name)
0 commit comments