Skip to content

Commit

Permalink
feat(compiler): add support for committing changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 17, 2024
1 parent a498580 commit 14e9439
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Expand Up @@ -9,8 +9,13 @@ import cc.unitmesh.devti.language.psi.DevInUsed
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.changes.ChangeListManager
import com.intellij.openapi.vcs.changes.CommitContext
import com.intellij.openapi.vcs.changes.LocalChangeList
import com.intellij.psi.PsiElement
import com.intellij.psi.util.elementType
import com.intellij.vcs.commit.ChangeListCommitState
import com.intellij.vcs.commit.LocalChangesCommitter

data class CompileResult(
var output: String = "",
Expand Down Expand Up @@ -67,6 +72,11 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
return
}

if (command.requireProps) {
processingCommand(command, "", used, fallbackText = used.text)
return
}

val propElement = id.nextSibling?.nextSibling
val isProp = (propElement.elementType == DevInTypes.COMMAND_PROP)
if (!isProp) {
Expand Down Expand Up @@ -188,9 +198,16 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
}


class CommitInsCommand(val myProject: Project, prop: String, val commitMsg: String?): InsCommand {
class CommitInsCommand(val myProject: Project, prop: String, val commitMsg: String) : InsCommand {
override fun execute(): String? {
TODO("Not yet implemented")
}
val changeListManager = ChangeListManager.getInstance(myProject)
changeListManager.changeLists.forEach {
val list: LocalChangeList = changeListManager.getChangeList(it.id) ?: return@forEach
val commitState = ChangeListCommitState(it, list.changes.toList(), commitMsg)
val committer = LocalChangesCommitter(myProject, commitState, CommitContext())
committer.runCommit("Commit", false)
}

return "Committing..."
}
}
Expand Up @@ -11,10 +11,11 @@ enum class BuiltinCommand(
val agentName: String,
val description: String,
val icon: Icon,
val hasCompletion: Boolean = false
val hasCompletion: Boolean = false,
val requireProps: Boolean = false,
) {
FILE("file", "Read the content of a file", AllIcons.Actions.AddFile, true),
REV("rev", "Read git change by file", AllIcons.Vcs.History, true),
FILE("file", "Read the content of a file", AllIcons.Actions.AddFile, true, true),
REV("rev", "Read git change by file", AllIcons.Vcs.History, true, true),
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName", AllIcons.Actions.GroupBy, false),
WRITE("write", "Write content to a file, /write:/path/to/file:L1-L2", AllIcons.Actions.Edit, false),
PATCH("patch", "Apply patch to a file, /patch:/path/to/file", AllIcons.Vcs.Patch_file, false),
Expand Down

0 comments on commit 14e9439

Please sign in to comment.