Skip to content

Commit

Permalink
feat(devins-lang): add support for built-in command examples #100
Browse files Browse the repository at this point in the history
This commit introduces a new feature to the DevInLanguage plugin that allows for the retrieval of built-in command examples.
  • Loading branch information
phodal committed Mar 28, 2024
1 parent 4676717 commit 68fd6b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
Expand Up @@ -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(
Expand Down Expand Up @@ -42,11 +43,22 @@ enum class BuiltinCommand(
;

companion object {

fun all(): List<BuiltinCommand> {
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 }
}
Expand Down
Expand Up @@ -5,6 +5,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.LiteralTextEscaper

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

override fun decode(rangeInsideHost: TextRange, outChars: StringBuilder): Boolean {
Expand Down Expand Up @@ -41,8 +42,4 @@ class CodeBlockLiteralTextEscaper(host: CodeBlockElement) : LiteralTextEscaper<C
result
} else -1
}

override fun getRelevantTextRange(): TextRange {
return CodeBlockElement.obtainRelevantTextRange(myHost)
}
}
@@ -0,0 +1,16 @@
package cc.unitmesh.devti.language.completion.dataprovider

import junit.framework.TestCase.assertEquals
import org.junit.Test

class BuiltinCommandTest {
@Test
fun shouldEnableGetBuiltinExamples() {
val commandList = BuiltinCommand.all()
val map = commandList.map {
BuiltinCommand.example(it)
}

assertEquals(commandList.size, map.size)
}
}

0 comments on commit 68fd6b6

Please sign in to comment.