Skip to content

Commit fab54c0

Browse files
committed
feat(devins-compiler): add support for custom commands #100
Add support for custom commands in the data provider, allowing the compiler to use custom commands defined in the project. This enables the DevInsCompiler to compile custom commands and integrate them into the output.
1 parent 4398cb9 commit fab54c0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.agent.model.CustomAgentConfig
44
import cc.unitmesh.devti.custom.compile.VariableTemplateCompiler
55
import cc.unitmesh.devti.language.compiler.exec.*
66
import cc.unitmesh.devti.language.dataprovider.BuiltinCommand
7+
import cc.unitmesh.devti.language.dataprovider.CustomCommand
78
import cc.unitmesh.devti.language.parser.CodeBlockElement
89
import cc.unitmesh.devti.language.psi.DevInFile
910
import cc.unitmesh.devti.language.psi.DevInTypes
@@ -62,6 +63,18 @@ class DevInsCompiler(
6263
DevInTypes.COMMAND_START -> {
6364
val command = BuiltinCommand.fromString(id?.text ?: "")
6465
if (command == null) {
66+
CustomCommand.fromString(myProject, id?.text ?: "")?.let { cmd ->
67+
DevInFile.fromString(myProject, cmd.content).let { file ->
68+
DevInsCompiler(myProject, file).compile().let {
69+
output.append(it.output)
70+
result.hasError = it.hasError
71+
}
72+
}
73+
74+
return
75+
}
76+
77+
6578
output.append(used.text)
6679
logger.warn("Unknown command: ${id?.text}")
6780
result.hasError = true

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/dataprovider/CustomCommand.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ data class CustomCommand(
2525
val content = file.inputStream.readBytes().toString(Charsets.UTF_8)
2626
return CustomCommand(file.nameWithoutExtension, content)
2727
}
28+
29+
fun fromString(project: Project, agentName: String): CustomCommand? {
30+
return all(project).find { it.commandName == agentName }
31+
}
2832
}
2933
}

0 commit comments

Comments
 (0)