From 146ecc4222bf0dfcc59eb933a93cb13877d4d9a0 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 29 Dec 2024 13:48:05 +0800 Subject: [PATCH] feat(completion): enhance custom agent completion with auto-insert 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. --- .../completion/provider/CustomAgentCompletion.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/completion/provider/CustomAgentCompletion.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/completion/provider/CustomAgentCompletion.kt index 95de41956..5c996c6a0 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/completion/provider/CustomAgentCompletion.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/completion/provider/CustomAgentCompletion.kt @@ -14,10 +14,14 @@ class CustomAgentCompletion : CompletionProvider() { result: CompletionResultSet, ) { val configs: List = 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)) } } }