Skip to content

Commit 14e9439

Browse files
committed
feat(compiler): add support for committing changes
This commit adds support for committing changes in the DevIns compiler. It introduces a new `CommitInsCommand` class that executes the commit operation using `LocalChangesCommitter`. The commit message is passed as a parameter to the `CommitInsCommand`. Additionally, the `BuiltinCommandProvider` now has a new property `requireProps`, which indicates if a command requires additional properties.
1 parent a498580 commit 14e9439

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ import cc.unitmesh.devti.language.psi.DevInUsed
99
import com.intellij.openapi.diagnostic.logger
1010
import com.intellij.openapi.editor.Editor
1111
import com.intellij.openapi.project.Project
12+
import com.intellij.openapi.vcs.changes.ChangeListManager
13+
import com.intellij.openapi.vcs.changes.CommitContext
14+
import com.intellij.openapi.vcs.changes.LocalChangeList
1215
import com.intellij.psi.PsiElement
1316
import com.intellij.psi.util.elementType
17+
import com.intellij.vcs.commit.ChangeListCommitState
18+
import com.intellij.vcs.commit.LocalChangesCommitter
1419

1520
data class CompileResult(
1621
var output: String = "",
@@ -67,6 +72,11 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
6772
return
6873
}
6974

75+
if (command.requireProps) {
76+
processingCommand(command, "", used, fallbackText = used.text)
77+
return
78+
}
79+
7080
val propElement = id.nextSibling?.nextSibling
7181
val isProp = (propElement.elementType == DevInTypes.COMMAND_PROP)
7282
if (!isProp) {
@@ -188,9 +198,16 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
188198
}
189199

190200

191-
class CommitInsCommand(val myProject: Project, prop: String, val commitMsg: String?): InsCommand {
201+
class CommitInsCommand(val myProject: Project, prop: String, val commitMsg: String) : InsCommand {
192202
override fun execute(): String? {
193-
TODO("Not yet implemented")
194-
}
203+
val changeListManager = ChangeListManager.getInstance(myProject)
204+
changeListManager.changeLists.forEach {
205+
val list: LocalChangeList = changeListManager.getChangeList(it.id) ?: return@forEach
206+
val commitState = ChangeListCommitState(it, list.changes.toList(), commitMsg)
207+
val committer = LocalChangesCommitter(myProject, commitState, CommitContext())
208+
committer.runCommit("Commit", false)
209+
}
195210

211+
return "Committing..."
212+
}
196213
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinCommandProvider.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ enum class BuiltinCommand(
1111
val agentName: String,
1212
val description: String,
1313
val icon: Icon,
14-
val hasCompletion: Boolean = false
14+
val hasCompletion: Boolean = false,
15+
val requireProps: Boolean = false,
1516
) {
16-
FILE("file", "Read the content of a file", AllIcons.Actions.AddFile, true),
17-
REV("rev", "Read git change by file", AllIcons.Vcs.History, true),
17+
FILE("file", "Read the content of a file", AllIcons.Actions.AddFile, true, true),
18+
REV("rev", "Read git change by file", AllIcons.Vcs.History, true, true),
1819
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName", AllIcons.Actions.GroupBy, false),
1920
WRITE("write", "Write content to a file, /write:/path/to/file:L1-L2", AllIcons.Actions.Edit, false),
2021
PATCH("patch", "Apply patch to a file, /patch:/path/to/file", AllIcons.Vcs.Patch_file, false),

0 commit comments

Comments
 (0)