Skip to content

Commit a498580

Browse files
committed
feat(devins-compiler): add support for commit command #101
Add support for the commit command in the DevInsCompiler. The commit command allows users to commit changes made to a file. If no code block is specified, the command will print a commit message.
1 parent 7521246 commit a498580

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
132132
}
133133
}
134134

135+
BuiltinCommand.COMMIT -> {
136+
result.isLocalCommand = true
137+
val devInCode: CodeBlockElement? = lookupNextCode(used)
138+
if (devInCode == null) {
139+
PrintInsCommand("/" + commandNode.agentName + ":" + prop)
140+
} else {
141+
CommitInsCommand(myProject, prop, devInCode.text)
142+
}
143+
}
144+
135145
BuiltinCommand.RUN -> {
136146
result.isLocalCommand = true
137147
RunInsCommand(myProject, prop)
@@ -142,7 +152,10 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
142152

143153
val isSucceed = execResult?.contains("<DevliError>") == false
144154
val result = if (isSucceed) {
145-
val hasReadCodeBlock = commandNode == BuiltinCommand.WRITE || commandNode == BuiltinCommand.PATCH
155+
val hasReadCodeBlock = commandNode == BuiltinCommand.WRITE
156+
|| commandNode == BuiltinCommand.PATCH
157+
|| commandNode == BuiltinCommand.COMMIT
158+
146159
if (hasReadCodeBlock) {
147160
skipNextCode = true
148161
}
@@ -175,3 +188,9 @@ class DevInsCompiler(private val myProject: Project, val file: DevInFile, val ed
175188
}
176189

177190

191+
class CommitInsCommand(val myProject: Project, prop: String, val commitMsg: String?): InsCommand {
192+
override fun execute(): String? {
193+
TODO("Not yet implemented")
194+
}
195+
196+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ enum class BuiltinCommand(
1515
) {
1616
FILE("file", "Read the content of a file", AllIcons.Actions.AddFile, true),
1717
REV("rev", "Read git change by file", AllIcons.Vcs.History, true),
18-
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName", AllIcons.Actions.GroupBy),
19-
WRITE("write", "Write content to a file, /write:/path/to/file:L1-L2", AllIcons.Actions.Edit),
20-
PATCH("patch", "Apply patch to a file, /patch:/path/to/file", AllIcons.Vcs.Patch_file),
21-
RUN("run", "Run the content of a file", AllIcons.Actions.Execute),
18+
SYMBOL("symbol", "Read content by Java/Kotlin canonicalName", AllIcons.Actions.GroupBy, false),
19+
WRITE("write", "Write content to a file, /write:/path/to/file:L1-L2", AllIcons.Actions.Edit, false),
20+
PATCH("patch", "Apply patch to a file, /patch:/path/to/file", AllIcons.Vcs.Patch_file, false),
21+
RUN("run", "Run the content of a file", AllIcons.Actions.Execute, false),
22+
COMMIT("commit", "Commit the content of a file", AllIcons.Vcs.CommitNode, false)
2223
;
2324

2425
companion object {

0 commit comments

Comments
 (0)