Skip to content

Commit ed9378b

Browse files
committed
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.
1 parent c57e7bd commit ed9378b

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cc.unitmesh.devti.language.compiler
2+
3+
import cc.unitmesh.devti.language.psi.DevInFile
4+
import cc.unitmesh.devti.language.psi.DevInTypes
5+
import cc.unitmesh.devti.language.psi.DevInUsed
6+
import com.intellij.openapi.diagnostic.logger
7+
import com.intellij.openapi.editor.Editor
8+
import com.intellij.openapi.project.Project
9+
import com.intellij.psi.util.elementType
10+
11+
class DevInCompiler(val project: Project, val file: DevInFile, val editor: Editor) {
12+
private val logger = logger<DevInCompiler>()
13+
private val output: StringBuilder = StringBuilder()
14+
15+
fun compile(): String {
16+
file.children.forEach {
17+
when (it.elementType) {
18+
DevInTypes.TEXT_SEGMENT -> output.append(it.text)
19+
DevInTypes.NEWLINE -> output.append("\n")
20+
DevInTypes.CODE -> {
21+
output.append(it.text)
22+
}
23+
24+
DevInTypes.USED -> {
25+
processUsed(it as DevInUsed)
26+
}
27+
28+
else -> {
29+
output.append(it.text)
30+
logger.warn("Unknown element type: ${it.elementType}")
31+
}
32+
}
33+
}
34+
35+
return output.toString()
36+
}
37+
38+
private fun processUsed(used: DevInUsed) {
39+
40+
}
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cc.unitmesh.devti.language.compiler
2+
3+
import cc.unitmesh.devti.language.psi.DevInFile
4+
import com.intellij.openapi.project.guessProjectDir
5+
import com.intellij.psi.PsiFile
6+
import com.intellij.testFramework.VfsTestUtil
7+
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
8+
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
9+
10+
class DevInCompilerTest : LightJavaCodeInsightFixtureTestCase() {
11+
fun testNormalString() {
12+
val code = "Normal String /"
13+
val file = myFixture.configureByText("test.devin", code)
14+
15+
val compile = DevInCompiler(project, file as DevInFile, myFixture.editor).compile()
16+
assertEquals("Normal String /", compile)
17+
}
18+
}
19+
20+

src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import kotlinx.coroutines.runBlocking
2727
import kotlinx.coroutines.flow.*
2828

2929
class CommitMessageSuggestionAction : ChatBaseAction() {
30-
3130
override fun getActionUpdateThread(): ActionUpdateThread {
3231
return ActionUpdateThread.BGT
3332
}

0 commit comments

Comments
 (0)