generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
.../devin-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinAgentProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cc.unitmesh.devti.language.completion | ||
|
||
import cc.unitmesh.devti.language.DevInIcons | ||
import com.intellij.codeInsight.completion.* | ||
import com.intellij.codeInsight.lookup.LookupElement | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder | ||
import com.intellij.util.ProcessingContext | ||
|
||
enum class BuiltinAgent(val agentName: String, val description: String) { | ||
FILE("file", "Read the content of a file"), | ||
REV("rev", "Read git revision of a file"), | ||
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName"), | ||
|
||
; | ||
|
||
companion object { | ||
fun all(): List<BuiltinAgent> { | ||
return values().toList() | ||
} | ||
} | ||
} | ||
|
||
class BuiltinAgentProvider : CompletionProvider<CompletionParameters>() { | ||
override fun addCompletions( | ||
parameters: CompletionParameters, | ||
context: ProcessingContext, | ||
result: CompletionResultSet, | ||
) { | ||
val builtinAgents = BuiltinAgent.all() | ||
builtinAgents.forEach { | ||
val withTypeText = LookupElementBuilder.create(it.agentName) | ||
.withIcon(DevInIcons.DEFAULT) | ||
.withTypeText(it.description, true) | ||
.withInsertHandler { context, _ -> | ||
context.document.insertString(context.tailOffset, ":") | ||
context.editor.caretModel.moveCaretRelatively(0, 1, false, false, false) | ||
} | ||
|
||
result.addElement(withTypeText) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters