Skip to content

Commit 68fd6b6

Browse files
committed
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.
1 parent 4676717 commit 68fd6b6

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

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

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

33
import cc.unitmesh.devti.language.DevInIcons
44
import com.intellij.icons.AllIcons
5+
import java.nio.charset.StandardCharsets
56
import javax.swing.Icon
67

78
enum class BuiltinCommand(
@@ -42,11 +43,22 @@ enum class BuiltinCommand(
4243
;
4344

4445
companion object {
45-
4646
fun all(): List<BuiltinCommand> {
4747
return values().toList()
4848
}
4949

50+
fun example(command: BuiltinCommand): String {
51+
val commandName = command.commandName
52+
val inputStream = BuiltinCommand::class.java.getResourceAsStream("/agent/toolExamples/$commandName.devin")
53+
if (inputStream == null) {
54+
throw IllegalStateException("Example file not found: $commandName.devin")
55+
}
56+
57+
return inputStream!!.use {
58+
it.readAllBytes().toString(StandardCharsets.UTF_8)
59+
}
60+
}
61+
5062
fun fromString(agentName: String): BuiltinCommand? {
5163
return values().find { it.commandName == agentName }
5264
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/parser/CodeBlockLiteralTextEscaper.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.intellij.openapi.util.TextRange
55
import com.intellij.psi.LiteralTextEscaper
66

77
class CodeBlockLiteralTextEscaper(host: CodeBlockElement) : LiteralTextEscaper<CodeBlockElement>(host) {
8+
override fun getRelevantTextRange() = CodeBlockElement.obtainRelevantTextRange(myHost)
89
override fun isOneLine(): Boolean = false;
910

1011
override fun decode(rangeInsideHost: TextRange, outChars: StringBuilder): Boolean {
@@ -41,8 +42,4 @@ class CodeBlockLiteralTextEscaper(host: CodeBlockElement) : LiteralTextEscaper<C
4142
result
4243
} else -1
4344
}
44-
45-
override fun getRelevantTextRange(): TextRange {
46-
return CodeBlockElement.obtainRelevantTextRange(myHost)
47-
}
4845
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cc.unitmesh.devti.language.completion.dataprovider
2+
3+
import junit.framework.TestCase.assertEquals
4+
import org.junit.Test
5+
6+
class BuiltinCommandTest {
7+
@Test
8+
fun shouldEnableGetBuiltinExamples() {
9+
val commandList = BuiltinCommand.all()
10+
val map = commandList.map {
11+
BuiltinCommand.example(it)
12+
}
13+
14+
assertEquals(commandList.size, map.size)
15+
}
16+
}

0 commit comments

Comments
 (0)