@@ -99,12 +99,29 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
99
99
e.presentation.description = " Generate commit message with AI"
100
100
}
101
101
102
- e.presentation.icon = AutoDevStatus .Ready .icon
102
+ // Update icon based on current job status
103
+ if (currentJob?.isActive == true ) {
104
+ e.presentation.icon = AutoDevStatus .InProgress .icon
105
+ e.presentation.text = " Cancel Commit Message Generation"
106
+ e.presentation.description = " Click to cancel current generation"
107
+ } else {
108
+ e.presentation.icon = AutoDevStatus .Ready .icon
109
+ }
110
+
103
111
e.presentation.isEnabled = changes.isNotEmpty()
104
112
}
105
113
106
114
override fun executeAction (event : AnActionEvent ) {
107
115
val project = event.project ? : return
116
+
117
+ // If there's an active job, cancel it
118
+ if (currentJob?.isActive == true ) {
119
+ currentJob?.cancel()
120
+ currentJob = null
121
+ AutoDevNotifications .notify(project, " Commit message generation cancelled." )
122
+ return
123
+ }
124
+
108
125
val commitMessage = getCommitMessage(event) ? : return
109
126
110
127
val commitWorkflowUi = VcsUtil .getCommitWorkFlowUi(event)
@@ -129,7 +146,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
129
146
if (isGitHubRepository) {
130
147
generateGitHubIssueCommitMessage(project, commitMessage, event)
131
148
} else {
132
- generateAICommitMessage(project, commitMessage, changes, event )
149
+ generateAICommitMessage(project, commitMessage, changes)
133
150
}
134
151
}
135
152
@@ -149,7 +166,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
149
166
if (issues.isEmpty()) {
150
167
// No issues found, fall back to AI generation
151
168
val changes = currentChanges ? : return @invokeLater
152
- generateAICommitMessage(project, commitMessage, changes, event )
169
+ generateAICommitMessage(project, commitMessage, changes)
153
170
} else {
154
171
createIssuesPopup(commitMessage, issues).showInBestPositionFor(event.dataContext)
155
172
}
@@ -159,7 +176,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
159
176
logger.warn(" Failed to fetch GitHub issues, falling back to AI generation" , ex)
160
177
// Fall back to AI generation when GitHub issues fetch fails
161
178
val changes = currentChanges ? : return @invokeLater
162
- generateAICommitMessage(project, commitMessage, changes, event )
179
+ generateAICommitMessage(project, commitMessage, changes)
163
180
}
164
181
}
165
182
}
@@ -304,7 +321,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
304
321
val event = currentEvent ? : return
305
322
306
323
// Generate AI commit message with issue context
307
- generateAICommitMessage(project, commitMessage, changes, event )
324
+ generateAICommitMessage(project, commitMessage, changes)
308
325
}
309
326
310
327
private fun handleSkipIssueSelection (commitMessage : CommitMessage ) {
@@ -316,10 +333,10 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
316
333
val event = currentEvent ? : return
317
334
318
335
// Generate AI commit message without issue context
319
- generateAICommitMessage(project, commitMessage, changes, event )
336
+ generateAICommitMessage(project, commitMessage, changes)
320
337
}
321
338
322
- private fun generateAICommitMessage (project : Project , commitMessage : CommitMessage , changes : List <Change >, event : AnActionEvent ) {
339
+ private fun generateAICommitMessage (project : Project , commitMessage : CommitMessage , changes : List <Change >) {
323
340
val diffContext = project.service<VcsPrompting >().prepareContext(changes)
324
341
if (diffContext.isEmpty() || diffContext == " \n " ) {
325
342
logger.warn(" Diff context is empty or cannot get enough useful context." )
@@ -332,7 +349,6 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
332
349
333
350
currentJob?.cancel()
334
351
editorField.text = " "
335
- event.presentation.icon = AutoDevStatus .InProgress .icon
336
352
337
353
ApplicationManager .getApplication().executeOnPooledThread {
338
354
val prompt = generateCommitMessage(diffContext, project, originText)
@@ -366,14 +382,13 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
366
382
AutoDevNotifications .notify(project, " Error generating commit message: ${e.message} " )
367
383
}
368
384
} finally {
369
- invokeLater {
370
- event.presentation.icon = AutoDevStatus .Ready .icon
371
- }
385
+ // Job completed, will be reflected in next update() call
386
+ currentJob = null
372
387
}
373
388
}
374
389
} catch (e: Exception ) {
375
390
logger.error(" Failed to start commit message generation" , e)
376
- event.presentation.icon = AutoDevStatus . Error .icon
391
+ currentJob = null
377
392
AutoDevNotifications .notify(project, " Failed to start commit message generation: ${e.message} " )
378
393
}
379
394
}
0 commit comments