Skip to content

Commit

Permalink
feat(completion): enhance custom agent completion with auto-insert
Browse files Browse the repository at this point in the history
Added an insert handler to automatically insert a space and move the caret after selecting a custom agent in the completion list. This improves the user experience by reducing manual steps.
  • Loading branch information
phodal committed Dec 29, 2024
1 parent 5a424fb commit 146ecc4
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class CustomAgentCompletion : CompletionProvider<CompletionParameters>() {
result: CompletionResultSet,
) {
val configs: List<CustomAgent> = CustomAgent.loadFromProject(parameters.originalFile.project)
configs.forEach {
result.addElement(LookupElementBuilder
.create("\"${it.name}\"")
.withTypeText(it.description, true))
configs.forEach { config ->
result.addElement(
LookupElementBuilder.create(config.name)
.withInsertHandler { context, _ ->
context.document.insertString(context.tailOffset, " ")
context.editor.caretModel.moveCaretRelatively(1, 0, false, true, false)
}
.withTypeText(config.description, true))
}
}
}

0 comments on commit 146ecc4

Please sign in to comment.