Skip to content

Commit a09cd0f

Browse files
committed
feat(completion): add support for built-in agent completion #101
This commit introduces a new completion provider for built-in agents in the DevInLanguage. It extends the completion type to include psi elements for agent identifiers and provides a list of built-in agents along with their descriptions. The completion provider also adds a custom insert handler to insert a colon after the agent name is selected, allowing for the specification of agent parameters.
1 parent 632372d commit a09cd0f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cc.unitmesh.devti.language.completion
2+
3+
import cc.unitmesh.devti.language.DevInIcons
4+
import com.intellij.codeInsight.completion.*
5+
import com.intellij.codeInsight.lookup.LookupElement
6+
import com.intellij.codeInsight.lookup.LookupElementBuilder
7+
import com.intellij.util.ProcessingContext
8+
9+
enum class BuiltinAgent(val agentName: String, val description: String) {
10+
FILE("file", "Read the content of a file"),
11+
REV("rev", "Read git revision of a file"),
12+
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName"),
13+
14+
;
15+
16+
companion object {
17+
fun all(): List<BuiltinAgent> {
18+
return values().toList()
19+
}
20+
}
21+
}
22+
23+
class BuiltinAgentProvider : CompletionProvider<CompletionParameters>() {
24+
override fun addCompletions(
25+
parameters: CompletionParameters,
26+
context: ProcessingContext,
27+
result: CompletionResultSet,
28+
) {
29+
val builtinAgents = BuiltinAgent.all()
30+
builtinAgents.forEach {
31+
val withTypeText = LookupElementBuilder.create(it.agentName)
32+
.withIcon(DevInIcons.DEFAULT)
33+
.withTypeText(it.description, true)
34+
.withInsertHandler { context, _ ->
35+
context.document.insertString(context.tailOffset, ":")
36+
context.editor.caretModel.moveCaretRelatively(0, 1, false, false, false)
37+
}
38+
39+
result.addElement(withTypeText)
40+
}
41+
}
42+
}
43+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class DevInCompletionContributor : CompletionContributor() {
1313
init {
1414
extend(CompletionType.BASIC, psiElement(DevInTypes.LANGUAGE_ID), CodeFenceLanguageProvider())
1515
extend(CompletionType.BASIC, psiElement(DevInTypes.VARIABLE_ID), CustomVariableProvider())
16+
extend(CompletionType.BASIC, psiElement(DevInTypes.AGENT_ID), BuiltinAgentProvider())
1617
}
1718

1819
override fun beforeCompletion(context: CompletionInitializationContext) {

0 commit comments

Comments
 (0)