Skip to content

Commit c7eee9a

Browse files
committed
feat(completion): refactor completion provider and add support for revision references #101
The completion provider for the DevIn language has been refactored to improve code organization and maintainability. The `DevInCompletionContributor` class has been simplified and moved to the `completion` package. Additionally, a new class `RevisionReferenceLanguageProvider` has been added to provide completion suggestions for git revisions. This provider retrieves the list of commits from the current branch and adds them as completion options. The `BuiltinAgentProvider` has been updated to reflect the change in the `REV` agent's description to better match its functionality.
1 parent 6140691 commit c7eee9a

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package cc.unitmesh.devti.language.completion
1+
package cc.unitmesh.devti.language
22

3+
import cc.unitmesh.devti.language.completion.*
34
import cc.unitmesh.devti.language.psi.DevInFile
45
import cc.unitmesh.devti.language.psi.DevInTypes
56
import cc.unitmesh.devti.language.psi.DevInUsed
@@ -22,6 +23,11 @@ class DevInCompletionContributor : CompletionContributor() {
2223
valuePattern(FileReferenceLanguageProvider.FILE_REF_TYPE),
2324
FileReferenceLanguageProvider()
2425
)
26+
extend(
27+
CompletionType.BASIC,
28+
valuePattern(RevisionReferenceLanguageProvider.REV_REF_TYPE),
29+
RevisionReferenceLanguageProvider()
30+
)
2531
}
2632

2733
override fun beforeCompletion(context: CompletionInitializationContext) {

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 revision of a file"),
10+
REV("rev", "Read git change by revision"),
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
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cc.unitmesh.devti.language.completion
2+
3+
import com.intellij.codeInsight.completion.CompletionParameters
4+
import com.intellij.codeInsight.completion.CompletionProvider
5+
import com.intellij.codeInsight.completion.CompletionResultSet
6+
import com.intellij.codeInsight.lookup.LookupElementBuilder
7+
import com.intellij.icons.AllIcons
8+
import com.intellij.openapi.project.Project
9+
import com.intellij.util.ProcessingContext
10+
import git4idea.GitCommit
11+
import git4idea.GitIcons
12+
import git4idea.history.GitHistoryUtils
13+
import git4idea.repo.GitRepositoryManager
14+
import git4idea.ui.branch.BranchIconUtil
15+
16+
17+
class RevisionReferenceLanguageProvider : CompletionProvider<CompletionParameters>() {
18+
companion object {
19+
const val REV_REF_TYPE = "rev"
20+
}
21+
22+
override fun addCompletions(
23+
parameters: CompletionParameters,
24+
context: ProcessingContext,
25+
result: CompletionResultSet,
26+
) {
27+
val project: Project = parameters.editor.project ?: return
28+
val repository = GitRepositoryManager.getInstance(project).repositories.firstOrNull() ?: return
29+
val branchName = repository.currentBranchName
30+
val commits: List<GitCommit> = GitHistoryUtils.history(project, repository.root, branchName)
31+
32+
commits.forEach {
33+
try {
34+
val element = LookupElementBuilder.create(it.fullMessage)
35+
.withIcon(AllIcons.Vcs.Branch)
36+
.withTypeText(it.id.toShortString(), true)
37+
38+
result.addElement(element)
39+
} catch (e: Exception) {
40+
// e.printStackTrace()
41+
}
42+
}
43+
}
44+
}

exts/devin-lang/src/main/resources/cc.unitmesh.devti.language.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<typedHandler implementation="cc.unitmesh.devti.language.DevInTypedHandler"/>
1919

2020
<completion.contributor language="DevIn"
21-
implementationClass="cc.unitmesh.devti.language.completion.DevInCompletionContributor"/>
21+
implementationClass="cc.unitmesh.devti.language.DevInCompletionContributor"/>
2222

2323
<lang.foldingBuilder language="DevIn"
2424
implementationClass="cc.unitmesh.devti.language.folding.DevInCustomVariableFoldingBuilder"/>

0 commit comments

Comments
 (0)