Skip to content

Commit

Permalink
fix(tasks): add onFinished() methods to notify application status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 5, 2024
1 parent e6f8628 commit 632be81
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/AutoDevNotifications.kt
Expand Up @@ -14,4 +14,10 @@ object AutoDevNotifications {
val notification = createNotificationGroup()?.createNotification(msg, NotificationType.INFORMATION)
notification?.notify(project)
}

// error
fun error(project: Project, msg: String) {
val notification = createNotificationGroup()?.createNotification(msg, NotificationType.ERROR)
notification?.notify(project)
}
}
Expand Up @@ -73,16 +73,20 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
logger.info(prompt)

event.presentation.icon = AutoDevStatus.InProgress.icon
val stream = LlmFactory().create(project).stream(prompt, "", false)

runBlocking {
stream.cancellable().collect {
invokeLater {
commitMessageUi.editorField.text += it
try {
val stream = LlmFactory().create(project).stream(prompt, "", false)

runBlocking {
stream.cancellable().collect {
invokeLater {
commitMessageUi.editorField.text += it
}
}
}

event.presentation.icon = AutoDevStatus.Ready.icon
event.presentation.icon = AutoDevStatus.Ready.icon
}
} catch (e: Exception) {
event.presentation.icon = AutoDevStatus.Error.icon
}
}
}
Expand Down
@@ -1,6 +1,7 @@
package cc.unitmesh.devti.intentions.action.task

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.AutoDevNotifications
import cc.unitmesh.devti.util.InsertUtil
import cc.unitmesh.devti.util.LLMCoroutineScope
import cc.unitmesh.devti.intentions.action.CodeCompletionBaseIntention
Expand Down Expand Up @@ -84,6 +85,12 @@ abstract class BaseCompletionTask(private val request: CodeCompletionRequest) :
}
}

override fun onThrowable(error: Throwable) {
super.onThrowable(error)
AutoDevNotifications.error(project, "Failed to completion: ${error.message}")
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
}

override fun onCancel() {
this.isCanceled = true
super.onCancel()
Expand Down
@@ -1,6 +1,7 @@
package cc.unitmesh.devti.intentions.action.task

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.AutoDevNotifications
import cc.unitmesh.devti.llms.LlmFactory
import cc.unitmesh.devti.provider.LivingDocumentation
import cc.unitmesh.devti.custom.document.LivingDocumentationType
Expand Down Expand Up @@ -50,6 +51,12 @@ class LivingDocumentationTask(
AutoDevStatusService.notifyApplication(AutoDevStatus.Ready)
}

override fun onThrowable(error: Throwable) {
super.onThrowable(error)
AutoDevNotifications.error(project, "Failed to generate living documentation: ${error.message}")
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
}

companion object {
private val logger = logger<LivingDocumentationTask>()
}
Expand Down
@@ -1,6 +1,7 @@
package cc.unitmesh.devti.intentions.action.task

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.AutoDevNotifications
import cc.unitmesh.devti.context.modifier.CodeModifierProvider
import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.intentions.action.AutoTestThisBaseIntention
Expand Down Expand Up @@ -137,6 +138,12 @@ class TestCodeGenTask(val request: TestCodeGenRequest) :
}
}

override fun onThrowable(error: Throwable) {
super.onThrowable(error)
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
AutoDevNotifications.error(project, "Failed to generate test: ${error.message}")
}

private suspend fun writeTestToFile(
project: Project,
flow: Flow<String>,
Expand Down

0 comments on commit 632be81

Please sign in to comment.