Skip to content

Commit

Permalink
refactor(vcs): enhance commit message suggestion action
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Nov 21, 2024
1 parent 57733f2 commit 5fae9d7
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import cc.unitmesh.devti.vcs.VcsPrompting
import cc.unitmesh.devti.statusbar.AutoDevStatus
import cc.unitmesh.devti.template.TemplateRender
import cc.unitmesh.devti.template.context.TemplateContext
import cc.unitmesh.devti.util.parser.Code
import cc.unitmesh.devti.vcs.VcsUtil
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
Expand All @@ -33,9 +34,10 @@ import kotlinx.coroutines.flow.*

class CommitMessageSuggestionAction : ChatBaseAction() {

init{
init {
presentationText("settings.autodev.others.commitMessage", templatePresentation)
}

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
Expand Down Expand Up @@ -96,10 +98,14 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
}
}
.cancellable().collect {
invokeLater {
commitMessageUi.editorField.text += it
invokeLater {
commitMessageUi.editorField.text += it
}
}
}
}

if (result.startsWith("```") && result.endsWith("```")) {
commitMessageUi.editorField.text = Code.parse(result).text
}
} catch (e: Exception) {
event.presentation.icon = AutoDevStatus.Error.icon
Expand Down

0 comments on commit 5fae9d7

Please sign in to comment.