1
1
package cc.unitmesh.devti.indexer
2
2
3
- import cc.unitmesh.devti.AutoDevIcons
4
3
import cc.unitmesh.devti.indexer.provider.LangDictProvider
5
4
import cc.unitmesh.devti.llms.LlmFactory
6
5
import cc.unitmesh.devti.settings.coder.coderSetting
@@ -15,6 +14,8 @@ import com.intellij.openapi.actionSystem.AnAction
15
14
import com.intellij.openapi.actionSystem.AnActionEvent
16
15
import com.intellij.openapi.project.guessProjectDir
17
16
import kotlinx.coroutines.launch
17
+ import cc.unitmesh.devti.AutoDevIcons
18
+ import com.intellij.openapi.actionSystem.Presentation
18
19
19
20
class DomainDictGenerateAction : AnAction () {
20
21
init {
@@ -23,6 +24,8 @@ class DomainDictGenerateAction : AnAction() {
23
24
24
25
override fun actionPerformed (event : AnActionEvent ) {
25
26
val project = event.project ? : return
27
+ val presentation = event.presentation
28
+
26
29
AutoDevCoroutineScope .scope(project).launch {
27
30
val names = LangDictProvider .all(project)
28
31
@@ -33,10 +36,10 @@ class DomainDictGenerateAction : AnAction() {
33
36
val prompt = templateRender.renderTemplate(template, context)
34
37
35
38
try {
36
- this @DomainDictGenerateAction.templatePresentation.icon = AutoDevIcons .InProgress
37
- this @DomainDictGenerateAction.templatePresentation.isEnabled = false
38
- val result = StringBuilder ()
39
+ updatePresentation(presentation, AutoDevIcons .InProgress , false )
39
40
AutoDevStatusService .notifyApplication(AutoDevStatus .InProgress )
41
+
42
+ val result = StringBuilder ()
40
43
LlmFactory .create(project).stream(prompt, " " ).collect {
41
44
result.append(it)
42
45
}
@@ -53,13 +56,18 @@ class DomainDictGenerateAction : AnAction() {
53
56
AutoDevStatusService .notifyApplication(AutoDevStatus .Error )
54
57
e.printStackTrace()
55
58
} finally {
56
- this @DomainDictGenerateAction.templatePresentation. icon = AutoDevIcons . AI_COPILOT
57
- this @DomainDictGenerateAction.templatePresentation.isEnabled = true
59
+ // Restore icon and enable the action
60
+ updatePresentation(presentation, AutoDevIcons . AI_COPILOT , true )
58
61
}
59
62
}
60
63
}
64
+
65
+ private fun updatePresentation (presentation : Presentation , icon : javax.swing.Icon , enabled : Boolean ) {
66
+ presentation.icon = icon
67
+ presentation.isEnabled = enabled
68
+ }
61
69
}
62
70
63
71
data class DomainDictGenerateContext (
64
72
val code : String
65
- ) : TemplateContext
73
+ ) : TemplateContext
0 commit comments