Skip to content

Commit 1ea0bb8

Browse files
committed
feat(compiler): add support for rev auto command #101
This commit introduces a new auto command for the compiler, which allows users to view the changes made in a specific revision. The command, `RevAutoCommand`, takes a project and a revision string as parameters and uses the GitRevisionNumber and GitCommittedChangeListProvider to retrieve the committed change list. The changes are then converted into a diff context using the `VcsPrompting` service and the `DiffSimplifier`. The output is appended to a StringBuilder for later display.
1 parent e74019a commit 1ea0bb8

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class DevInCompiler(val myProject: Project, val file: DevInFile, val editor: Edi
8989
}
9090

9191
BuiltinCommand.REV -> {
92-
logger.info("handling rev")
93-
output.append(command.agentName)
92+
val result = RevAutoCommand(myProject, prop).execute() ?: fallbackText
93+
output.append(result)
9494
}
9595

9696
BuiltinCommand.SYMBOL -> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.intellij.openapi.util.TextRange
77
import com.intellij.openapi.vfs.VirtualFileManager
88
import com.intellij.psi.PsiManager
99

10-
class FileAutoCommand(val myProject: Project, val prop: String) : AutoCommand {
10+
class FileAutoCommand(private val myProject: Project, private val prop: String) : AutoCommand {
1111
private val logger = logger<FileAutoCommand>()
1212
private val output = StringBuilder()
1313

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cc.unitmesh.devti.language.compiler
2+
3+
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.vcs.VcsPrompting
5+
import com.intellij.codeInsight.lookup.LookupElementBuilder
6+
import com.intellij.icons.AllIcons
7+
import com.intellij.openapi.components.service
8+
import com.intellij.openapi.progress.ProgressIndicator
9+
import com.intellij.openapi.progress.ProgressManager
10+
import com.intellij.openapi.progress.Task
11+
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
12+
import com.intellij.openapi.progress.runBlockingCancellable
13+
import com.intellij.openapi.project.Project
14+
import com.intellij.openapi.vcs.changes.Change
15+
import git4idea.GitCommit
16+
import git4idea.GitRevisionNumber
17+
import git4idea.changes.GitCommittedChangeList
18+
import git4idea.changes.GitCommittedChangeListProvider
19+
import git4idea.history.GitHistoryUtils
20+
import git4idea.repo.GitRepositoryManager
21+
import kotlinx.coroutines.future.await
22+
import kotlinx.coroutines.runBlocking
23+
import java.util.concurrent.CompletableFuture
24+
25+
26+
class RevAutoCommand(private val myProject: Project, private val revision: String) : AutoCommand {
27+
override fun execute(): String? {
28+
val repository = GitRepositoryManager.getInstance(myProject).repositories.firstOrNull() ?: return null
29+
30+
// val changeList =
31+
// GitCommittedChangeListProvider.getCommittedChangeList(
32+
// myProject,
33+
// repository.root,
34+
// GitRevisionNumber(revision)
35+
// )
36+
37+
// return changeList?.changes?.joinToString("\n") { it.toString() }
38+
39+
val future = CompletableFuture<List<Change>>()
40+
val task = object : Task.Backgroundable(myProject, AutoDevBundle.message("devin.ref.loading"), false) {
41+
override fun run(indicator: ProgressIndicator) {
42+
val committedChangeList = GitCommittedChangeListProvider.getCommittedChangeList(
43+
myProject!!,
44+
repository.root,
45+
GitRevisionNumber(revision)
46+
)
47+
48+
49+
future.complete(committedChangeList?.changes?.toList())
50+
}
51+
}
52+
53+
ProgressManager.getInstance()
54+
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
55+
56+
57+
return runBlocking {
58+
val changes = future.await()
59+
val diffContext = myProject.service<VcsPrompting>().prepareContext(changes)
60+
"\n```diff\n${diffContext}\n```\n"
61+
}
62+
}
63+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class FileReferenceLanguageProvider : CompletionProvider<CompletionParameters>()
1919
val recentlyFiles = EditorHistoryManager.getInstance(project).fileList
2020

2121
// TODO: file should be in project
22-
2322
recentlyFiles.forEach {
2423
val removePrefix = it.path.removePrefix(basePath)
2524
val relativePath: String = removePrefix.removePrefix(File.separator)

src/main/kotlin/cc/unitmesh/devti/vcs/VcsPrompting.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class VcsPrompting(private val project: Project) {
4141
FileSystems.getDefault().getPathMatcher("glob:$it")
4242
}
4343

44-
fun prepareContext(changes: List<Change>): String {
45-
return project.service<DiffSimplifier>().simplify(changes, defaultIgnoreFilePatterns)
44+
fun prepareContext(changes: List<Change>, ignoreFilePatterns: List<PathMatcher> = defaultIgnoreFilePatterns): String {
45+
return project.service<DiffSimplifier>().simplify(changes, ignoreFilePatterns)
4646
}
4747

4848
/**

0 commit comments

Comments
 (0)