diff --git a/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/project/Project.kt b/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/project/Project.kt index 18b7456..daf0fc6 100644 --- a/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/project/Project.kt +++ b/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/project/Project.kt @@ -28,7 +28,7 @@ class Project( loadCohesiveProject() } - createCohesiveProjectListener(parentDir.absolutePath) { + /*createCohesiveProjectListener(parentDir.absolutePath) { onCreate { //TODO handle modify file } @@ -42,7 +42,7 @@ class Project( GlobalScope.launch { startListening() } - } + }*/ projectLoaded = true } diff --git a/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/ui/impl/view/Editor.kt b/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/ui/impl/view/Editor.kt index c11f1bc..5f2ad71 100644 --- a/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/ui/impl/view/Editor.kt +++ b/cmpe/common/src/commonMain/kotlin/xyz/mcxross/cohesive/ui/impl/view/Editor.kt @@ -198,32 +198,87 @@ fun codeString( val punctuationCharacters = listOf(":", "=", "\"", "[", "]", "{", "}", "(", ")", ",") val keywords = listOf( - "fun", "val", "var", "private", "internal", "for", - "expect", "actual", "import", "package", + "script", + "module", + "self", + "const", + "native", + "public", + "public(friend)", + "internal", + "entry", + "fun", + "has", + "drop", + "key", + "store", + "acquires", + "struct", + "use", + "as", + "mut", + "copy", + "move", + "return", + "abort", + "break", + "continue", + "if", + "else", + "loop", + "while", + "let", + "phantom", + "spec", ) + + // Identify and store the ranges of all comments + val commentRanges = mutableListOf() + for (result in """^\s*//.*""".toRegex(RegexOption.MULTILINE).findAll(strFormatted)) { + commentRanges.add(result.range) + addStyle(theme.code.comment, result.range.first, result.range.last + 1) // Style the comment immediately + } + for (punctuation in punctuationCharacters) { - addStyle(theme.code.punctuation, strFormatted, punctuation) + val matches = Regex.escape(punctuation).toRegex().findAll(strFormatted) + for (match in matches) { + if (!isInCommentRange(match.range.first, commentRanges)) { + addStyle(theme.code.punctuation, match.range.first, match.range.last + 1) + } + } } + for (keyword in keywords) { - addStyle(theme.code.keyword, strFormatted, keyword) + val matches = """\b$keyword\b""".toRegex().findAll(strFormatted) + for (match in matches) { + if (!isInCommentRange(match.range.first, commentRanges)) { + addStyle(theme.code.keyword, match.range.first, match.range.last + 1) + } + } } - - addStyle(theme.code.value, strFormatted, "true") - addStyle(theme.code.value, strFormatted, "false") - addStyle(theme.code.value, strFormatted, Regex("[0-9]*")) - addStyle(theme.code.annotation, strFormatted, Regex("^@[a-zA-Z_]*")) - addStyle(theme.code.comment, strFormatted, Regex("^\\s*//.*")) + addStyle(theme.code.value, strFormatted, """\btrue\b""") + addStyle(theme.code.value, strFormatted, """\bfalse\b""") + addStyle(theme.code.value, strFormatted, """\b[0-9]+\b""") + addStyle(theme.code.annotation, strFormatted, """\b@[a-zA-Z_]+\b""") } } +private fun isInCommentRange(index: Int, commentRanges: List): Boolean { + for (range in commentRanges) { + if (range.contains(index)) { + return true + } + } + return false +} private fun AnnotatedString.Builder.addStyle( style: SpanStyle, text: String, regexp: String, ) { - addStyle(style, text, Regex.fromLiteral(regexp)) + addStyle(style, text, Regex(regexp)) } private fun AnnotatedString.Builder.addStyle( @@ -236,6 +291,7 @@ private fun AnnotatedString.Builder.addStyle( } } + @Composable fun EditorEmpty( text: String = "No file opened", diff --git a/cmpe/common/src/desktopMain/kotlin/xyz/mcxross/cohesive/extension/File.kt b/cmpe/common/src/desktopMain/kotlin/xyz/mcxross/cohesive/extension/File.kt index 86935e2..d2d892f 100644 --- a/cmpe/common/src/desktopMain/kotlin/xyz/mcxross/cohesive/extension/File.kt +++ b/cmpe/common/src/desktopMain/kotlin/xyz/mcxross/cohesive/extension/File.kt @@ -69,7 +69,7 @@ fun java.io.File.toProjectFile(): File = return object : TextLines { override val size get() = size - override var isCode: Boolean = name.endsWith(".kt", ignoreCase = true) + override var isCode: Boolean = name.endsWith(".move", ignoreCase = true) override val text: State get() { return if (byteBuffer.hasArray()) { diff --git a/cmpe/csp/build.gradle.kts b/cmpe/csp/build.gradle.kts index 81785c1..19547e7 100644 --- a/cmpe/csp/build.gradle.kts +++ b/cmpe/csp/build.gradle.kts @@ -27,7 +27,7 @@ sourceSets.main { java.srcDirs("src/main/kotlin") } publishing { publications { create("maven") { - groupId = "com.mcxross.cohesive" + groupId = "xyz.mcxross.cohesive" artifactId = "cohesive-csp" from(components["java"]) }