Skip to content

Commit eb60574

Browse files
committed
feat(completion): improve built-in agent support for file and revision 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.
1 parent c7eee9a commit eb60574

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/DevInCompletionContributor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class DevInCompletionContributor : CompletionContributor() {
2020
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.AGENT_ID), BuiltinAgentProvider())
2121
extend(
2222
CompletionType.BASIC,
23-
valuePattern(FileReferenceLanguageProvider.FILE_REF_TYPE),
23+
valuePattern(BuiltinAgent.FILE.agentName),
2424
FileReferenceLanguageProvider()
2525
)
2626
extend(
2727
CompletionType.BASIC,
28-
valuePattern(RevisionReferenceLanguageProvider.REV_REF_TYPE),
28+
valuePattern(BuiltinAgent.REV.agentName),
2929
RevisionReferenceLanguageProvider()
3030
)
3131
}

exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinAgentProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.intellij.util.ProcessingContext
77

88
enum class BuiltinAgent(val agentName: String, val description: String) {
99
FILE("file", "Read the content of a file"),
10-
REV("rev", "Read git change by revision"),
10+
REV("rev", "Read git change by file"),
1111
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName"),
1212
WRITE("write", "Write content to a file, format: /write:/path/to/file:L1-C2"),
1313
;

exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/RevisionReferenceLanguageProvider.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ import com.intellij.icons.AllIcons
88
import com.intellij.openapi.project.Project
99
import com.intellij.util.ProcessingContext
1010
import git4idea.GitCommit
11-
import git4idea.GitIcons
1211
import git4idea.history.GitHistoryUtils
1312
import git4idea.repo.GitRepositoryManager
14-
import git4idea.ui.branch.BranchIconUtil
1513

1614

1715
class RevisionReferenceLanguageProvider : CompletionProvider<CompletionParameters>() {
18-
companion object {
19-
const val REV_REF_TYPE = "rev"
20-
}
21-
2216
override fun addCompletions(
2317
parameters: CompletionParameters,
2418
context: ProcessingContext,
@@ -27,18 +21,18 @@ class RevisionReferenceLanguageProvider : CompletionProvider<CompletionParameter
2721
val project: Project = parameters.editor.project ?: return
2822
val repository = GitRepositoryManager.getInstance(project).repositories.firstOrNull() ?: return
2923
val branchName = repository.currentBranchName
30-
val commits: List<GitCommit> = GitHistoryUtils.history(project, repository.root, branchName)
3124

32-
commits.forEach {
33-
try {
25+
try {
26+
val commits: List<GitCommit> = GitHistoryUtils.history(project, repository.root, branchName)
27+
commits.forEach {
3428
val element = LookupElementBuilder.create(it.fullMessage)
3529
.withIcon(AllIcons.Vcs.Branch)
3630
.withTypeText(it.id.toShortString(), true)
3731

3832
result.addElement(element)
39-
} catch (e: Exception) {
40-
// e.printStackTrace()
4133
}
34+
} catch (e: Exception) {
35+
// e.printStackTrace()
4236
}
4337
}
4438
}

0 commit comments

Comments
 (0)