[FIR] Add rendering of error numbers per file/package/module in HTML dump

This commit is contained in:
Dmitriy Novozhilov
2019-11-01 12:41:30 +03:00
parent 528e538b2a
commit 829227255d
4 changed files with 34 additions and 3 deletions
@@ -78,4 +78,8 @@ body.dark {
.dark .line { .dark .line {
background-color: #313335; background-color: #313335;
border-right: thin solid darkgray; border-right: thin solid darkgray;
}
.dark .error-counter {
color: #ff1010;
} }
@@ -67,4 +67,8 @@
.white .line { .white .line {
background-color: lightgray; background-color: lightgray;
border-right: thin solid darkgray; border-right: thin solid darkgray;
}
.white .error-counter {
color: #f00;
} }
@@ -58,4 +58,8 @@ a.ref {
.line { .line {
margin-right: 5px; margin-right: 5px;
}
.error-counter {
margin-left: 10px;
} }
@@ -69,7 +69,7 @@ private class PackageInfo(val fqName: FqName, val moduleInfo: ModuleInfo) {
val packageRoot = fqName.pathSegments().fold(moduleInfo.moduleRoot) { dir, segment -> dir.resolve(segment.asString()) }.also { val packageRoot = fqName.pathSegments().fold(moduleInfo.moduleRoot) { dir, segment -> dir.resolve(segment.asString()) }.also {
it.mkdirs() it.mkdirs()
} }
val errors = mutableMapOf<String, Int>().withDefault { 0 }
} }
private class ModuleInfo(val name: String, outputRoot: File) { private class ModuleInfo(val name: String, outputRoot: File) {
@@ -77,6 +77,9 @@ private class ModuleInfo(val name: String, outputRoot: File) {
val moduleRoot = outputRoot.resolve(name).also { val moduleRoot = outputRoot.resolve(name).also {
it.mkdirs() it.mkdirs()
} }
val errors: Map<FqName, Int> by lazy {
packages.mapValues { (_, packageInfo) -> packageInfo.errors.values.sum() }.withDefault { 0 }
}
} }
private class SupplementaryGenerator(val outputRoot: File) { private class SupplementaryGenerator(val outputRoot: File) {
@@ -106,6 +109,7 @@ private class SupplementaryGenerator(val outputRoot: File) {
) { ) {
+packageInfo.fqName.asString() +packageInfo.fqName.asString()
} }
addErrors(moduleInfo.errors.getValue(packageInfo.fqName))
} }
} }
} }
@@ -113,6 +117,12 @@ private class SupplementaryGenerator(val outputRoot: File) {
} }
} }
fun LI.addErrors(errors: Int) {
if (errors > 0) {
span(classes = "error-counter") { +(errors.toString()) }
}
}
fun linkToIndex(moduleInfo: ModuleInfo, from: File): String { fun linkToIndex(moduleInfo: ModuleInfo, from: File): String {
return moduleInfo.moduleRoot.resolve(MODULE_INDEX).relativeTo(from).path return moduleInfo.moduleRoot.resolve(MODULE_INDEX).relativeTo(from).path
} }
@@ -148,6 +158,7 @@ private class SupplementaryGenerator(val outputRoot: File) {
for (file in packageInfo.contents) { for (file in packageInfo.contents) {
li { li {
a(href = "./$file.fir.html", classes = "container-ref") { +file } a(href = "./$file.fir.html", classes = "container-ref") { +file }
addErrors(packageInfo.errors.getValue(file))
} }
} }
} }
@@ -170,6 +181,7 @@ private class SupplementaryGenerator(val outputRoot: File) {
for (module in modules) { for (module in modules) {
li { li {
a(href = linkToIndex(module, outputRoot), classes = "container-ref") { +module.name } a(href = linkToIndex(module, outputRoot), classes = "container-ref") { +module.name }
addErrors(module.errors.values.sum())
} }
} }
} }
@@ -273,6 +285,9 @@ class MultiModuleHtmlFirDump(private val outputRoot: File) {
dumper.generate(file, builder) dumper.generate(file, builder)
dumpOutput.writeText(builder.toString()) dumpOutput.writeText(builder.toString())
packageForFile(file).apply {
errors[file.name] = dumper.errors
}
} }
@@ -368,12 +383,15 @@ class MultiModuleHtmlFirDump(private val outputRoot: File) {
} }
class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver, private val session: FirSession) { class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver, private val session: FirSession) {
var errors: Int = 0
private set
fun generate(element: FirFile, builder: StringBuilder): Int {
fun generate(element: FirFile, builder: StringBuilder) { errors = 0
builder.appendHTML().html { builder.appendHTML().html {
generate(element) generate(element)
} }
return errors
} }
private fun FlowContent.keyword(text: String) { private fun FlowContent.keyword(text: String) {
@@ -414,6 +432,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
} }
private fun FlowContent.error(block: SPAN.() -> Unit) { private fun FlowContent.error(block: SPAN.() -> Unit) {
errors++
span(classes = "error") { span(classes = "error") {
block() block()
} }