File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed
kotlin/cc/unitmesh/devti/language
resources/agent/toolExamples
test/kotlin/cc/unitmesh/devti/language/completion/dataprovider Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package cc.unitmesh.devti.language.completion.dataprovider
2
2
3
3
import cc.unitmesh.devti.language.DevInIcons
4
4
import com.intellij.icons.AllIcons
5
+ import java.nio.charset.StandardCharsets
5
6
import javax.swing.Icon
6
7
7
8
enum class BuiltinCommand (
@@ -42,11 +43,22 @@ enum class BuiltinCommand(
42
43
;
43
44
44
45
companion object {
45
-
46
46
fun all (): List <BuiltinCommand > {
47
47
return values().toList()
48
48
}
49
49
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
+
50
62
fun fromString (agentName : String ): BuiltinCommand ? {
51
63
return values().find { it.commandName == agentName }
52
64
}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import com.intellij.openapi.util.TextRange
5
5
import com.intellij.psi.LiteralTextEscaper
6
6
7
7
class CodeBlockLiteralTextEscaper (host : CodeBlockElement ) : LiteralTextEscaper<CodeBlockElement>(host) {
8
+ override fun getRelevantTextRange () = CodeBlockElement .obtainRelevantTextRange(myHost)
8
9
override fun isOneLine (): Boolean = false ;
9
10
10
11
override fun decode (rangeInsideHost : TextRange , outChars : StringBuilder ): Boolean {
@@ -41,8 +42,4 @@ class CodeBlockLiteralTextEscaper(host: CodeBlockElement) : LiteralTextEscaper<C
41
42
result
42
43
} else - 1
43
44
}
44
-
45
- override fun getRelevantTextRange (): TextRange {
46
- return CodeBlockElement .obtainRelevantTextRange(myHost)
47
- }
48
45
}
File renamed without changes.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments