Skip to content

Commit

Permalink
fix(completion): improve completion provider for DevInTypes.COLON #101
Browse files Browse the repository at this point in the history
The completion provider for DevInTypes.COLON has been updated to use a more specific file pattern instead of a generic pattern, ensuring that completion suggestions are more relevant to the context of a colon symbol. This change also simplifies the provider configuration, making it easier to maintain and understand.

Additionally, the BuiltinAgentProvider has been refactored to remove unnecessary imports and code related to the insertion of a colon after the completion. The provider now simply adds elements to the completion result set, without any additional handling for the colon insertion. This simplifies the code and improves readability.
  • Loading branch information
phodal committed Mar 14, 2024
1 parent 1c58f51 commit 7f0c1cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Expand Up @@ -2,15 +2,13 @@ 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 {
Expand All @@ -26,17 +24,12 @@ class BuiltinAgentProvider : CompletionProvider<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)
BuiltinAgent.all().forEach {
result.addElement(
LookupElementBuilder.create(it.agentName)
.withIcon(DevInIcons.DEFAULT)
.withTypeText(it.description, true)
)
}
}
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ class DevInCompletionContributor : CompletionContributor() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.LANGUAGE_ID), CodeFenceLanguageProvider())
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.VARIABLE_ID), CustomVariableProvider())
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.AGENT_ID), BuiltinAgentProvider())
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.COLON), CodeFenceLanguageProvider())
extend(CompletionType.BASIC, filePattern(), CodeFenceLanguageProvider())
}

override fun beforeCompletion(context: CompletionInitializationContext) {
Expand Down

0 comments on commit 7f0c1cb

Please sign in to comment.