Skip to content

Commit 2908e41

Browse files
committed
feat(devins-lang): add support for flow control in DevInsPromptProcessor.kt and DevInsCompiler.kt #100
1 parent 84c0700 commit 2908e41

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiledResult.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.language.compiler
22

33
import cc.unitmesh.devti.agent.model.CustomAgentConfig
4+
import cc.unitmesh.devti.language.psi.DevInFile
45

56
data class DevInsCompiledResult(
67
/**
@@ -13,6 +14,10 @@ data class DevInsCompiledResult(
1314
var output: String = "",
1415
var isLocalCommand: Boolean = false,
1516
var hasError: Boolean = false,
16-
var executeAgent: CustomAgentConfig? = null
17+
var executeAgent: CustomAgentConfig? = null,
18+
/**
19+
* Next job to be executed
20+
*/
21+
var nextJob: DevInFile? = null
1722
) {
1823
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import cc.unitmesh.devti.language.psi.DevInUsed
1414
import com.intellij.openapi.diagnostic.logger
1515
import com.intellij.openapi.editor.Editor
1616
import com.intellij.openapi.project.Project
17+
import com.intellij.openapi.project.guessProjectDir
1718
import com.intellij.psi.PsiElement
1819
import com.intellij.psi.util.elementType
1920
import kotlinx.coroutines.runBlocking
@@ -48,10 +49,23 @@ class DevInsCompiler(
4849

4950
output.append(it.text)
5051
}
52+
5153
DevInTypes.USED -> processUsed(it as DevInUsed)
5254
DevInTypes.COMMENTS -> {
53-
// ignore comment
55+
if (it.text.startsWith("[flow]:")) {
56+
val fileName = it.text.substringAfter("[flow]:").trim()
57+
val content =
58+
myProject.guessProjectDir()?.findFileByRelativePath(fileName)?.let { virtualFile ->
59+
virtualFile.inputStream.bufferedReader().use { reader -> reader.readText() }
60+
}
61+
62+
if (content != null) {
63+
val devInFile = DevInFile.fromString(myProject, content)
64+
result.nextJob = devInFile
65+
}
66+
}
5467
}
68+
5569
else -> {
5670
output.append(it.text)
5771
logger.warn("Unknown element type: ${it.elementType}")

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/provider/DevInsPromptProcessor.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class DevInsPromptProcessor : LanguagePromptProcessor {
2929
val devInsCompiler = createCompiler(project, text)
3030
val result = devInsCompiler.compile()
3131
AutoDevNotifications.notify(project, result.output)
32+
33+
if (result.nextJob != null) {
34+
val nextJob = result.nextJob!!
35+
val nextResult = createCompiler(project, nextJob).compile()
36+
AutoDevNotifications.notify(project, nextResult.output)
37+
return nextResult.output
38+
}
39+
3240
return result.output
3341
}
3442

@@ -50,6 +58,13 @@ class DevInsPromptProcessor : LanguagePromptProcessor {
5058
text: String
5159
): DevInsCompiler {
5260
val devInFile = DevInFile.fromString(project, text)
61+
return createCompiler(project, devInFile)
62+
}
63+
64+
private fun createCompiler(
65+
project: Project,
66+
devInFile: DevInFile
67+
): DevInsCompiler {
5368
val editor = FileEditorManager.getInstance(project).selectedTextEditor
5469
val element: PsiElement? = editor?.caretModel?.currentCaret?.offset?.let {
5570
val psiFile = PsiUtilBase.getPsiFileInEditor(editor, project) ?: return@let null

0 commit comments

Comments
 (0)