[Editor] Create working scaffolding for compilation logs pane

This commit is contained in:
2021-02-25 08:59:12 +01:00
parent 049d75dc65
commit a139e31da8
2 changed files with 43 additions and 8 deletions

View File

@@ -16,10 +16,19 @@ class JavaCompiler : ScriptCompiler {
val files = sourceDirectory.allChildren.map(FileSystemNode::file).filter(File::isFile)
val compiler = compilerFactory.newCompiler()
// FIXME:
// For some reason the compiler's error handler does not want to catch
// syntax errors. The only way to catch it is just catching CompileExceptions
try {
compiler.compile(files.toTypedArray())
} catch (e: CompileException) {
FX.eventbus.fire(UpdateCompilationLogEvent(e.message ?: "", e.location))
// Because the Janino compiler assemblies the message with the location
// in the LocatedException.getMessage() method, we just need to remove it
// to have a plain message along with the plain location as separated objects
FX.eventbus.fire(
UpdateCompilationLogEvent(e.message?.substring(e.location.toString().length) ?: "", e.location)
)
}
}
}

View File

@@ -1,22 +1,48 @@
package com.bartlomiejpluta.base.editor.code.view
import com.bartlomiejpluta.base.editor.event.UpdateCompilationLogEvent
import org.fxmisc.richtext.CodeArea
import com.bartlomiejpluta.base.editor.main.controller.MainController
import javafx.scene.Cursor
import javafx.scene.paint.Color
import javafx.scene.text.Text
import org.codehaus.commons.compiler.Location
import org.fxmisc.richtext.StyledTextArea
import tornadofx.View
import tornadofx.enableWhen
import tornadofx.toProperty
class CompilerLogsView : View() {
private val editor = CodeArea().apply {
enableWhen(false.toProperty())
}
private val mainController: MainController by di()
private val editor = StyledTextArea(null, { _, _ -> }, LocationRef.NO_LINK, { text, style -> style.apply(text) })
init {
subscribe<UpdateCompilationLogEvent> {
editor.clear()
editor.replaceText(0, 0, it.message)
val locationRef = LocationRef(it.location) { loc ->
// TODO(mainController.openScript(getFileSystemNodeFromSomewhere(loc)))
}
editor.insert(editor.length, it.location.toString(), locationRef)
editor.insert(editor.length, it.message, LocationRef.NO_LINK)
}
}
override val root = editor
class LocationRef(private val location: Location?, private val onClick: (Location) -> Unit = {}) {
private constructor() : this(null)
fun apply(text: Text) = location?.let { loc ->
text.cursor = Cursor.HAND
text.fill = Color.BLUE
text.isUnderline = true
text.setOnMouseClicked {
onClick(loc)
}
}
companion object {
val NO_LINK = LocationRef()
}
}
}