Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group by message template at the top level #13

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/jsMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ private
fun problemNodesByMessage(problems: List<ImportedProblem>): Sequence<List<ProblemNode>> =
problems.asSequence().map { problem ->
buildList {
add(problemNodeFor(problem))
add(problemTemplateNodeFor(problem))
add(messageNodeFor(problem))
addAll(problem.trace)
addExceptionNode(problem)
}
Expand Down Expand Up @@ -265,6 +266,14 @@ fun problemNodeFor(problem: ImportedProblem) = errorOrWarningNodeFor(
)


private
fun problemTemplateNodeFor(problem: ImportedProblem) = errorOrWarningNodeFor(
problem.problem,
messageTemplateNodeFor(problem),
docLinkFor(problem.problem)
)


private
fun toPrettyText(message: Array<JsMessageFragment>) = PrettyText(
message.map {
Expand Down Expand Up @@ -333,6 +342,21 @@ fun messageNodeFor(importedProblem: ImportedProblem) =
ProblemNode.Message(importedProblem.message)


private
fun messageTemplateNodeFor(importedProblem: ImportedProblem) =
ProblemNode.Message(importedProblem.message.toTemplate())


private
fun PrettyText.toTemplate(): PrettyText =
PrettyText(fragments.map {
when (it) {
is PrettyText.Fragment.Reference -> PrettyText.Fragment.Reference("___")
else -> it
}
})


private
fun exceptionNodeFor(diagnostic: JsDiagnostic): ProblemNode? {
val error = diagnostic.error ?: return null
Expand Down