Skip to content

Commit

Permalink
feat(devin-lang): add DevInCompilerTest and DevInCompiler classes to …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
phodal committed Mar 15, 2024
1 parent c57e7bd commit ed9378b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<DevInCompiler>()
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) {

}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.flow.*

class CommitMessageSuggestionAction : ChatBaseAction() {

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
Expand Down

0 comments on commit ed9378b

Please sign in to comment.