Skip to content

Commit 5fae9d7

Browse files
committed
refactor(vcs): enhance commit message suggestion action
Update the CommitMessageSuggestionAction to include a new import for Code utility and refactor the code structure. Specifically, this change adds proper indentation, wraps the invokeLater call in a cancellable collection, and introduces a condition to parse code blocks when starting and ending with ``` markers.
1 parent 57733f2 commit 5fae9d7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

exts/ext-git/src/main/kotlin/cc/unitmesh/git/actions/vcs/CommitMessageSuggestionAction.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import cc.unitmesh.devti.vcs.VcsPrompting
1010
import cc.unitmesh.devti.statusbar.AutoDevStatus
1111
import cc.unitmesh.devti.template.TemplateRender
1212
import cc.unitmesh.devti.template.context.TemplateContext
13+
import cc.unitmesh.devti.util.parser.Code
1314
import cc.unitmesh.devti.vcs.VcsUtil
1415
import com.intellij.openapi.actionSystem.ActionUpdateThread
1516
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -33,9 +34,10 @@ import kotlinx.coroutines.flow.*
3334

3435
class CommitMessageSuggestionAction : ChatBaseAction() {
3536

36-
init{
37+
init {
3738
presentationText("settings.autodev.others.commitMessage", templatePresentation)
3839
}
40+
3941
override fun getActionUpdateThread(): ActionUpdateThread {
4042
return ActionUpdateThread.BGT
4143
}
@@ -96,10 +98,14 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
9698
}
9799
}
98100
.cancellable().collect {
99-
invokeLater {
100-
commitMessageUi.editorField.text += it
101+
invokeLater {
102+
commitMessageUi.editorField.text += it
103+
}
101104
}
102-
}
105+
}
106+
107+
if (result.startsWith("```") && result.endsWith("```")) {
108+
commitMessageUi.editorField.text = Code.parse(result).text
103109
}
104110
} catch (e: Exception) {
105111
event.presentation.icon = AutoDevStatus.Error.icon

0 commit comments

Comments
 (0)