Skip to content

Commit 7b79a33

Browse files
committed
feat(devins-compiler): Use VariableTemplateCompiler for variable compilation #101
Add support for using VariableTemplateCompiler to compile variables. The compiler is now utilized to parse and compile variables, generating output based on the compilation.
1 parent 553bcba commit 7b79a33

File tree

1 file changed

+17
-4
lines changed
  • exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
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.custom.compile.VariableTemplateCompiler
45
import cc.unitmesh.devti.language.compiler.exec.*
56
import cc.unitmesh.devti.language.dataprovider.BuiltinCommand
67
import cc.unitmesh.devti.language.parser.CodeBlockElement
@@ -13,7 +14,12 @@ import com.intellij.openapi.project.Project
1314
import com.intellij.psi.PsiElement
1415
import com.intellij.psi.util.elementType
1516

16-
class DevInsCompiler(private val myProject: Project, val file: DevInFile, val editor: Editor? = null) {
17+
class DevInsCompiler(
18+
private val myProject: Project,
19+
private val file: DevInFile,
20+
private val editor: Editor? = null,
21+
private val element: PsiElement? = null
22+
) {
1723
private var skipNextCode: Boolean = false
1824
private val logger = logger<DevInsCompiler>()
1925
private val result = CompileResult()
@@ -91,9 +97,16 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
9197
}
9298

9399
DevInTypes.VARIABLE_START -> {
94-
/**
95-
* Todo, call [cc.unitmesh.devti.custom.compile.VariableTemplateCompiler]
96-
*/
100+
if (editor == null || element == null) {
101+
output.append("<DevInsError> No context editor found for variable: ${used.text}")
102+
result.hasError = true
103+
return
104+
}
105+
106+
val file = element.containingFile
107+
VariableTemplateCompiler(file.language, file, element, editor).compile(used.text).let {
108+
output.append(it)
109+
}
97110
}
98111

99112
else -> {

0 commit comments

Comments
 (0)