diff --git a/lib/src/commonMain/kotlin/world/phantasmal/lib/asm/Assembly.kt b/lib/src/commonMain/kotlin/world/phantasmal/lib/asm/Assembly.kt index eccbf69d..b0a60280 100644 --- a/lib/src/commonMain/kotlin/world/phantasmal/lib/asm/Assembly.kt +++ b/lib/src/commonMain/kotlin/world/phantasmal/lib/asm/Assembly.kt @@ -15,7 +15,7 @@ class AssemblyProblem( cause: Throwable? = null, val lineNo: Int, val col: Int, - val length: Int, + val len: Int, ) : Problem(severity, uiMessage, message, cause) fun assemble( @@ -214,7 +214,7 @@ private class Assembler(private val asm: List, private val inlineStackAr } } - private fun addError(col: Int, length: Int, uiMessage: String, message: String? = null) { + private fun addError(col: Int, len: Int, uiMessage: String, message: String? = null) { result.addProblem( AssemblyProblem( Severity.Error, @@ -222,7 +222,7 @@ private class Assembler(private val asm: List, private val inlineStackAr message ?: "$uiMessage At $lineNo:$col.", lineNo = lineNo, col = col, - length = length + len = len ) ) } @@ -246,7 +246,7 @@ private class Assembler(private val asm: List, private val inlineStackAr uiMessage, lineNo = lineNo, col = token.col, - length = token.len, + len = token.len, ) ) } @@ -375,7 +375,9 @@ private class Assembler(private val asm: List, private val inlineStackAr addError( identToken.col, errorLength, - "Expected $paramCount argument ${if (paramCount == 1) "" else "s"}, got $argCount.", + "Expected $paramCount argument${ + if (paramCount == 1) "" else "s" + }, got $argCount.", ) return @@ -385,7 +387,9 @@ private class Assembler(private val asm: List, private val inlineStackAr addError( identToken.col, errorLength, - "Expected at least $paramCount argument${if (paramCount == 1) "" else "s"}, got $argCount.", + "Expected at least $paramCount argument${ + if (paramCount == 1) "" else "s" + }, got $argCount.", ) return diff --git a/web/assembly-worker/src/main/kotlin/world/phantasmal/web/assemblyWorker/AssemblyWorker.kt b/web/assembly-worker/src/main/kotlin/world/phantasmal/web/assemblyWorker/AssemblyWorker.kt index 0d02afcc..8921a8b9 100644 --- a/web/assembly-worker/src/main/kotlin/world/phantasmal/web/assemblyWorker/AssemblyWorker.kt +++ b/web/assembly-worker/src/main/kotlin/world/phantasmal/web/assemblyWorker/AssemblyWorker.kt @@ -158,7 +158,7 @@ class AssemblyWorker(private val sendMessage: (ServerMessage) -> Unit) { @Suppress("UNCHECKED_CAST") val problems = (assemblyResult.problems as List).map { - AssemblyProblem(it.severity, it.uiMessage) + AssemblyProblem(it.severity, it.uiMessage, it.lineNo, it.col, it.len) } if (problems != this.problems) { diff --git a/web/shared/src/main/kotlin/world/phantasmal/web/shared/Messages.kt b/web/shared/src/main/kotlin/world/phantasmal/web/shared/Messages.kt index 2d90c540..8bd857be 100644 --- a/web/shared/src/main/kotlin/world/phantasmal/web/shared/Messages.kt +++ b/web/shared/src/main/kotlin/world/phantasmal/web/shared/Messages.kt @@ -157,4 +157,7 @@ class AsmChange( class AssemblyProblem( val severity: Severity, val message: String, + val lineNo: Int, + val col: Int, + val len: Int, ) diff --git a/web/src/main/kotlin/world/phantasmal/web/externals/monacoEditor/editor.kt b/web/src/main/kotlin/world/phantasmal/web/externals/monacoEditor/editor.kt index 685c8959..4e305733 100644 --- a/web/src/main/kotlin/world/phantasmal/web/externals/monacoEditor/editor.kt +++ b/web/src/main/kotlin/world/phantasmal/web/externals/monacoEditor/editor.kt @@ -22,6 +22,11 @@ external fun createModel( external fun defineTheme(themeName: String, themeData: IStandaloneThemeData) +/** + * Set the markers for a model. + */ +external fun setModelMarkers(model: ITextModel, owner: String, markers: Array) + external interface IStandaloneThemeData { var base: String /* 'vs' | 'vs-dark' | 'hc-black' */ var inherit: Boolean diff --git a/web/src/main/kotlin/world/phantasmal/web/questEditor/stores/AsmStore.kt b/web/src/main/kotlin/world/phantasmal/web/questEditor/stores/AsmStore.kt index 1e374310..5a64bd0b 100644 --- a/web/src/main/kotlin/world/phantasmal/web/questEditor/stores/AsmStore.kt +++ b/web/src/main/kotlin/world/phantasmal/web/questEditor/stores/AsmStore.kt @@ -1,6 +1,7 @@ package world.phantasmal.web.questEditor.stores import kotlinx.browser.window +import world.phantasmal.core.Severity import world.phantasmal.core.disposable.Disposer import world.phantasmal.core.disposable.disposable import world.phantasmal.lib.asm.assemble @@ -78,6 +79,35 @@ class AsmStore( observe(asmAnalyser.mapDesignations) { questEditorStore.currentQuest.value?.setMapDesignations(it) } + + observe(problems) { problems -> + textModel.value?.let { model -> + val markers = Array(problems.size) { + val problem = problems[it] + obj { + severity = when (problem.severity) { + Severity.Trace, Severity.Debug -> MarkerSeverity.Hint + Severity.Info -> MarkerSeverity.Info + Severity.Warning -> MarkerSeverity.Warning + Severity.Error -> MarkerSeverity.Error + } + message = problem.message + startLineNumber = problem.lineNo + startColumn = problem.col + endLineNumber = problem.lineNo + endColumn = problem.col + problem.len + + // Hack: because only one warning is generated at the moment, "Unnecessary + // section marker.", we can simply add the Unnecessary tag here. + if (problem.severity == Severity.Warning) { + tags = arrayOf(MarkerTag.Unnecessary) + } + } + } + // Not sure what the "owner" parameter is for. + setModelMarkers(model, owner = ASM_LANG_ID, markers) + } + } } fun makeUndoCurrent() {