Skip to content

Commit bb1c989

Browse files
committed
feat(devins-lang): extract toolhub for variables #100
Added AgentToolOverviewCompletion for DevIns language code completion. Replaced AgentToolLibraryCompletion with new class to provide completions for agents and commands in DevIns language code. Added ToolHub enum to manage types of completions and customized completion behavior accordingly.
1 parent af25d73 commit bb1c989

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

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

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DevInCompletionContributor : CompletionContributor() {
1717
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.LANGUAGE_ID), CodeFenceLanguageCompletion())
1818

1919
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.VARIABLE_ID), VariableCompletionProvider())
20-
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.VARIABLE_ID), AgentToolLibraryCompletion())
20+
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.VARIABLE_ID), AgentToolOverviewCompletion())
2121

2222
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.COMMAND_ID), BuiltinCommandCompletion())
2323
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.AGENT_ID), CustomAgentCompletion())

0 commit comments

Comments
 (0)