Skip to content

Commit ceb59b9

Browse files
committed
Display internal errors in the build window
1 parent 9dd49dd commit ceb59b9

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
- The build window will now display internal compiler errors as well.
7+
58
## [1.2.0] - 2023-08-18
69

710
### Added

src/main/kotlin/io/runescript/plugin/ide/execution/build/RsBuildOutputParser.kt

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.intellij.build.FilePosition
44
import com.intellij.build.events.BuildEvent
55
import com.intellij.build.events.MessageEvent
66
import com.intellij.build.events.impl.FileMessageEventImpl
7+
import com.intellij.build.events.impl.MessageEventImpl
78
import com.intellij.build.output.BuildOutputInstantReader
89
import com.intellij.build.output.BuildOutputParser
910
import java.io.File
@@ -14,15 +15,21 @@ class RsBuildOutputParser(private val instance: RsBuildInstance) : BuildOutputPa
1415
private val fileMessageContext = FileMessageContext()
1516
private val detailsBuilder = StringBuilder()
1617
private var detailsCount = 0
18+
private var collectingStackTrace = false
1719

18-
override fun parse(line: String, reader: BuildOutputInstantReader, messageConsumer: Consumer<in BuildEvent>): Boolean {
20+
override fun parse(
21+
line: String,
22+
reader: BuildOutputInstantReader,
23+
messageConsumer: Consumer<in BuildEvent>
24+
): Boolean {
1925
if (detailsCount > 0) {
2026
detailsCount--
2127
detailsBuilder.appendLine(line)
2228
if (detailsCount == 0) {
2329
val filePath = File(fileMessageContext.path)
2430
val filePosition = FilePosition(filePath, fileMessageContext.line, fileMessageContext.column)
25-
val fileMessage = FileMessageEventImpl(instance.buildId,
31+
val fileMessage = FileMessageEventImpl(
32+
instance.buildId,
2633
MessageEvent.Kind.ERROR,
2734
"Compiler Errors",
2835
fileMessageContext.message,
@@ -45,12 +52,39 @@ class RsBuildOutputParser(private val instance: RsBuildInstance) : BuildOutputPa
4552
detailsCount = 2
4653
return true
4754
}
55+
if (collectingStackTrace) {
56+
if (line.startsWith("Process finished")) {
57+
val fileMessage = MessageEventImpl(
58+
instance.buildId,
59+
MessageEvent.Kind.ERROR,
60+
"Compiler Errors",
61+
"Internal Error",
62+
detailsBuilder.toString()
63+
)
64+
messageConsumer.accept(fileMessage)
65+
collectingStackTrace = false
66+
} else {
67+
detailsBuilder.appendLine(line)
68+
}
69+
} else if (line.startsWith(EXCEPTION_BEGINNING)) {
70+
detailsBuilder.setLength(0)
71+
val exceptionLine = line.substring(line.indexOf('"', EXCEPTION_BEGINNING.length) + 2)
72+
detailsBuilder.appendLine(exceptionLine)
73+
collectingStackTrace = true
74+
}
4875
return false
4976
}
5077

5178
companion object {
52-
private val ERROR_PATTERN = Regex("(?<path>.+):(?<line>\\d+):(?<column>\\d+): (?:ERROR|SYNTAX_ERROR): (?<message>[^\\r\\n]+)")
79+
private val ERROR_PATTERN =
80+
Regex("(?<path>.+):(?<line>\\d+):(?<column>\\d+): (?:ERROR|SYNTAX_ERROR): (?<message>[^\\r\\n]+)")
81+
private const val EXCEPTION_BEGINNING = "Exception in thread \""
5382
}
5483
}
5584

56-
private data class FileMessageContext(var path: String = "", var line: Int = 0, var column: Int = 0, var message: String = "")
85+
private data class FileMessageContext(
86+
var path: String = "",
87+
var line: Int = 0,
88+
var column: Int = 0,
89+
var message: String = ""
90+
)

0 commit comments

Comments
 (0)