Skip to content

Commit 632be81

Browse files
committed
fix(tasks): add onFinished() methods to notify application status
These changes add `onFinished()` methods to various tasks to ensure that the application status is properly notified upon task completion. This enhancement ensures that the AutoDevStatusService is informed when tasks are finished, allowing for better status tracking and communication within the application.
1 parent e6f8628 commit 632be81

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

src/main/kotlin/cc/unitmesh/devti/AutoDevNotifications.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ object AutoDevNotifications {
1414
val notification = createNotificationGroup()?.createNotification(msg, NotificationType.INFORMATION)
1515
notification?.notify(project)
1616
}
17+
18+
// error
19+
fun error(project: Project, msg: String) {
20+
val notification = createNotificationGroup()?.createNotification(msg, NotificationType.ERROR)
21+
notification?.notify(project)
22+
}
1723
}

src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,20 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
7373
logger.info(prompt)
7474

7575
event.presentation.icon = AutoDevStatus.InProgress.icon
76-
val stream = LlmFactory().create(project).stream(prompt, "", false)
77-
78-
runBlocking {
79-
stream.cancellable().collect {
80-
invokeLater {
81-
commitMessageUi.editorField.text += it
76+
try {
77+
val stream = LlmFactory().create(project).stream(prompt, "", false)
78+
79+
runBlocking {
80+
stream.cancellable().collect {
81+
invokeLater {
82+
commitMessageUi.editorField.text += it
83+
}
8284
}
83-
}
8485

85-
event.presentation.icon = AutoDevStatus.Ready.icon
86+
event.presentation.icon = AutoDevStatus.Ready.icon
87+
}
88+
} catch (e: Exception) {
89+
event.presentation.icon = AutoDevStatus.Error.icon
8690
}
8791
}
8892
}

src/main/kotlin/cc/unitmesh/devti/intentions/action/task/BaseCompletionTask.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.intentions.action.task
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.AutoDevNotifications
45
import cc.unitmesh.devti.util.InsertUtil
56
import cc.unitmesh.devti.util.LLMCoroutineScope
67
import cc.unitmesh.devti.intentions.action.CodeCompletionBaseIntention
@@ -84,6 +85,12 @@ abstract class BaseCompletionTask(private val request: CodeCompletionRequest) :
8485
}
8586
}
8687

88+
override fun onThrowable(error: Throwable) {
89+
super.onThrowable(error)
90+
AutoDevNotifications.error(project, "Failed to completion: ${error.message}")
91+
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
92+
}
93+
8794
override fun onCancel() {
8895
this.isCanceled = true
8996
super.onCancel()

src/main/kotlin/cc/unitmesh/devti/intentions/action/task/LivingDocumentationTask.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.intentions.action.task
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.AutoDevNotifications
45
import cc.unitmesh.devti.llms.LlmFactory
56
import cc.unitmesh.devti.provider.LivingDocumentation
67
import cc.unitmesh.devti.custom.document.LivingDocumentationType
@@ -50,6 +51,12 @@ class LivingDocumentationTask(
5051
AutoDevStatusService.notifyApplication(AutoDevStatus.Ready)
5152
}
5253

54+
override fun onThrowable(error: Throwable) {
55+
super.onThrowable(error)
56+
AutoDevNotifications.error(project, "Failed to generate living documentation: ${error.message}")
57+
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
58+
}
59+
5360
companion object {
5461
private val logger = logger<LivingDocumentationTask>()
5562
}

src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.intentions.action.task
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.AutoDevNotifications
45
import cc.unitmesh.devti.context.modifier.CodeModifierProvider
56
import cc.unitmesh.devti.gui.chat.ChatActionType
67
import cc.unitmesh.devti.intentions.action.AutoTestThisBaseIntention
@@ -137,6 +138,12 @@ class TestCodeGenTask(val request: TestCodeGenRequest) :
137138
}
138139
}
139140

141+
override fun onThrowable(error: Throwable) {
142+
super.onThrowable(error)
143+
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
144+
AutoDevNotifications.error(project, "Failed to generate test: ${error.message}")
145+
}
146+
140147
private suspend fun writeTestToFile(
141148
project: Project,
142149
flow: Flow<String>,

0 commit comments

Comments
 (0)