From ed9378b21086830c6b23135b7f48b813e5730edc Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 15 Mar 2024 17:29:16 +0800 Subject: [PATCH] feat(devin-lang): add DevInCompilerTest and DevInCompiler classes to support DevInFile compilation and testing. #101 These new classes provide a foundation for compiling and testing DevInFile content, ensuring that the language features are correctly interpreted and processed. The DevInCompilerTest class includes a test case for normal string compilation, verifying the correct output. The DevInCompiler class is responsible for compiling a DevInFile, handling different element types within the file and providing a StringBuilder output. This commit lays the groundwork for further development and testing of the DevInFile compiler. --- .../devti/language/compiler/DevInCompiler.kt | 41 +++++++++++++++++++ .../language/compiler/DevInCompilerTest.kt | 20 +++++++++ .../vcs/CommitMessageSuggestionAction.kt | 1 - 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInCompiler.kt create mode 100644 exts/devin-lang/src/test/kotlin/cc/unitmesh/devti/language/compiler/DevInCompilerTest.kt diff --git a/exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInCompiler.kt b/exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInCompiler.kt new file mode 100644 index 0000000000..f096ae7729 --- /dev/null +++ b/exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInCompiler.kt @@ -0,0 +1,41 @@ +package cc.unitmesh.devti.language.compiler + +import cc.unitmesh.devti.language.psi.DevInFile +import cc.unitmesh.devti.language.psi.DevInTypes +import cc.unitmesh.devti.language.psi.DevInUsed +import com.intellij.openapi.diagnostic.logger +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.util.elementType + +class DevInCompiler(val project: Project, val file: DevInFile, val editor: Editor) { + private val logger = logger() + private val output: StringBuilder = StringBuilder() + + fun compile(): String { + file.children.forEach { + when (it.elementType) { + DevInTypes.TEXT_SEGMENT -> output.append(it.text) + DevInTypes.NEWLINE -> output.append("\n") + DevInTypes.CODE -> { + output.append(it.text) + } + + DevInTypes.USED -> { + processUsed(it as DevInUsed) + } + + else -> { + output.append(it.text) + logger.warn("Unknown element type: ${it.elementType}") + } + } + } + + return output.toString() + } + + private fun processUsed(used: DevInUsed) { + + } +} \ No newline at end of file diff --git a/exts/devin-lang/src/test/kotlin/cc/unitmesh/devti/language/compiler/DevInCompilerTest.kt b/exts/devin-lang/src/test/kotlin/cc/unitmesh/devti/language/compiler/DevInCompilerTest.kt new file mode 100644 index 0000000000..b171a2330d --- /dev/null +++ b/exts/devin-lang/src/test/kotlin/cc/unitmesh/devti/language/compiler/DevInCompilerTest.kt @@ -0,0 +1,20 @@ +package cc.unitmesh.devti.language.compiler + +import cc.unitmesh.devti.language.psi.DevInFile +import com.intellij.openapi.project.guessProjectDir +import com.intellij.psi.PsiFile +import com.intellij.testFramework.VfsTestUtil +import com.intellij.testFramework.fixtures.CodeInsightTestFixture +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase + +class DevInCompilerTest : LightJavaCodeInsightFixtureTestCase() { + fun testNormalString() { + val code = "Normal String /" + val file = myFixture.configureByText("test.devin", code) + + val compile = DevInCompiler(project, file as DevInFile, myFixture.editor).compile() + assertEquals("Normal String /", compile) + } +} + + diff --git a/src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt b/src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt index d9c13cc03b..6d470745b6 100644 --- a/src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt +++ b/src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt @@ -27,7 +27,6 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.flow.* class CommitMessageSuggestionAction : ChatBaseAction() { - override fun getActionUpdateThread(): ActionUpdateThread { return ActionUpdateThread.BGT }