|
| 1 | +package cc.unitmesh.devti.language.completion |
| 2 | + |
| 3 | +import cc.unitmesh.devti.agent.model.CustomAgentConfig |
| 4 | +import cc.unitmesh.devti.language.DevInIcons |
| 5 | +import cc.unitmesh.devti.language.dataprovider.BuiltinCommand |
| 6 | +import com.intellij.codeInsight.completion.CompletionParameters |
| 7 | +import com.intellij.codeInsight.completion.CompletionProvider |
| 8 | +import com.intellij.codeInsight.completion.CompletionResultSet |
| 9 | +import com.intellij.codeInsight.completion.PrioritizedLookupElement |
| 10 | +import com.intellij.codeInsight.lookup.LookupElementBuilder |
| 11 | +import com.intellij.util.ProcessingContext |
| 12 | + |
| 13 | +enum class ToolHub(val summaryName: String, val type: String, val description: String) { |
| 14 | + AGENT("Agent", CustomAgentConfig::class.simpleName.toString(), "DevIns all agent for AI Agent to call"), |
| 15 | + COMMAND("Command", BuiltinCommand::class.simpleName.toString(), "DevIns all commands for AI Agent to call"), |
| 16 | + |
| 17 | + ; |
| 18 | + |
| 19 | + companion object { |
| 20 | + fun all(): List<ToolHub> { |
| 21 | + return values().toList() |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +class AgentToolOverviewCompletion : CompletionProvider<CompletionParameters>() { |
| 27 | + override fun addCompletions( |
| 28 | + parameters: CompletionParameters, |
| 29 | + context: ProcessingContext, |
| 30 | + result: CompletionResultSet |
| 31 | + ) { |
| 32 | + ToolHub.all().forEach { toolHub -> |
| 33 | + val elements = LookupElementBuilder.create(toolHub.summaryName) |
| 34 | + .withIcon(DevInIcons.DEFAULT) |
| 35 | + .withTypeText(toolHub.type, true) |
| 36 | + .withPresentableText(toolHub.summaryName) |
| 37 | + .withTailText(toolHub.description, true) |
| 38 | + result.addElement(PrioritizedLookupElement.withPriority(elements, 0.0)) |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
0 commit comments