From 68fd6b6afcc58144255494829d3631a041b4b207 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 28 Mar 2024 14:00:05 +0800 Subject: [PATCH] feat(devins-lang): add support for built-in command examples #100 This commit introduces a new feature to the DevInLanguage plugin that allows for the retrieval of built-in command examples. --- .../completion/dataprovider/BuiltinCommand.kt | 14 +++++++++++++- .../parser/CodeBlockLiteralTextEscaper.kt | 5 +---- .../{fine-func.devin => file-func.devin} | 0 .../dataprovider/BuiltinCommandTest.kt | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) rename exts/devins-lang/src/main/resources/agent/toolExamples/{fine-func.devin => file-func.devin} (100%) create mode 100644 exts/devins-lang/src/test/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommandTest.kt diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt index 5cf2e83947..329c979c7a 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt @@ -2,6 +2,7 @@ package cc.unitmesh.devti.language.completion.dataprovider import cc.unitmesh.devti.language.DevInIcons import com.intellij.icons.AllIcons +import java.nio.charset.StandardCharsets import javax.swing.Icon enum class BuiltinCommand( @@ -42,11 +43,22 @@ enum class BuiltinCommand( ; companion object { - fun all(): List { return values().toList() } + fun example(command: BuiltinCommand): String { + val commandName = command.commandName + val inputStream = BuiltinCommand::class.java.getResourceAsStream("/agent/toolExamples/$commandName.devin") + if (inputStream == null) { + throw IllegalStateException("Example file not found: $commandName.devin") + } + + return inputStream!!.use { + it.readAllBytes().toString(StandardCharsets.UTF_8) + } + } + fun fromString(agentName: String): BuiltinCommand? { return values().find { it.commandName == agentName } } diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/parser/CodeBlockLiteralTextEscaper.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/parser/CodeBlockLiteralTextEscaper.kt index 1c00bb3118..0df516814d 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/parser/CodeBlockLiteralTextEscaper.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/parser/CodeBlockLiteralTextEscaper.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.LiteralTextEscaper class CodeBlockLiteralTextEscaper(host: CodeBlockElement) : LiteralTextEscaper(host) { + override fun getRelevantTextRange() = CodeBlockElement.obtainRelevantTextRange(myHost) override fun isOneLine(): Boolean = false; override fun decode(rangeInsideHost: TextRange, outChars: StringBuilder): Boolean { @@ -41,8 +42,4 @@ class CodeBlockLiteralTextEscaper(host: CodeBlockElement) : LiteralTextEscaper