diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt index 3b9a7cc951..fb387da93f 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt @@ -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 = "", @@ -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) { @@ -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..." + } } diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinCommandProvider.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinCommandProvider.kt index a311d5d98f..356f97d0d3 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinCommandProvider.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/BuiltinCommandProvider.kt @@ -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),