Skip to content

Commit

Permalink
feat(completion): improve built-in agent support for file and revisio…
Browse files Browse the repository at this point in the history
…n references #101

The completion system for the DevInT language has been enhanced to provide better support for built-in agents. Specifically, the completion provider now uses the `BuiltinAgent.FILE` and `BuiltinAgent.REV` constants instead of hard-coded strings, which improves maintainability and reduces the likelihood of typos. Additionally, the `RevisionReferenceLanguageProvider` has been updated to retrieve commits by their file changes instead of by revision, which aligns better with the new agent naming scheme and provides a more intuitive completion experience for users.
  • Loading branch information
phodal committed Mar 14, 2024
1 parent c7eee9a commit eb60574
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class DevInCompletionContributor : CompletionContributor() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.AGENT_ID), BuiltinAgentProvider())
extend(
CompletionType.BASIC,
valuePattern(FileReferenceLanguageProvider.FILE_REF_TYPE),
valuePattern(BuiltinAgent.FILE.agentName),
FileReferenceLanguageProvider()
)
extend(
CompletionType.BASIC,
valuePattern(RevisionReferenceLanguageProvider.REV_REF_TYPE),
valuePattern(BuiltinAgent.REV.agentName),
RevisionReferenceLanguageProvider()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 change by revision"),
REV("rev", "Read git change by file"),
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName"),
WRITE("write", "Write content to a file, format: /write:/path/to/file:L1-C2"),
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@ import com.intellij.icons.AllIcons
import com.intellij.openapi.project.Project
import com.intellij.util.ProcessingContext
import git4idea.GitCommit
import git4idea.GitIcons
import git4idea.history.GitHistoryUtils
import git4idea.repo.GitRepositoryManager
import git4idea.ui.branch.BranchIconUtil


class RevisionReferenceLanguageProvider : CompletionProvider<CompletionParameters>() {
companion object {
const val REV_REF_TYPE = "rev"
}

override fun addCompletions(
parameters: CompletionParameters,
context: ProcessingContext,
Expand All @@ -27,18 +21,18 @@ class RevisionReferenceLanguageProvider : CompletionProvider<CompletionParameter
val project: Project = parameters.editor.project ?: return
val repository = GitRepositoryManager.getInstance(project).repositories.firstOrNull() ?: return
val branchName = repository.currentBranchName
val commits: List<GitCommit> = GitHistoryUtils.history(project, repository.root, branchName)

commits.forEach {
try {
try {
val commits: List<GitCommit> = GitHistoryUtils.history(project, repository.root, branchName)
commits.forEach {
val element = LookupElementBuilder.create(it.fullMessage)
.withIcon(AllIcons.Vcs.Branch)
.withTypeText(it.id.toShortString(), true)

result.addElement(element)
} catch (e: Exception) {
// e.printStackTrace()
}
} catch (e: Exception) {
// e.printStackTrace()
}
}
}

0 comments on commit eb60574

Please sign in to comment.