Skip to content

Commit ff77786

Browse files
committed
refactor(indexer): improve domain dictionary generation and UI handling #358
Extract presentation update logic into separate method for reuse. Exclude test/utility classes from dictionary. Clean up imports and variable naming. This enhances maintainability and clarifies dictionary scope.
1 parent 93c23d9 commit ff77786

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

core/src/main/kotlin/cc/unitmesh/devti/indexer/DomainDictGenerateAction.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cc.unitmesh.devti.indexer
22

3-
import cc.unitmesh.devti.AutoDevIcons
43
import cc.unitmesh.devti.indexer.provider.LangDictProvider
54
import cc.unitmesh.devti.llms.LlmFactory
65
import cc.unitmesh.devti.settings.coder.coderSetting
@@ -15,6 +14,8 @@ import com.intellij.openapi.actionSystem.AnAction
1514
import com.intellij.openapi.actionSystem.AnActionEvent
1615
import com.intellij.openapi.project.guessProjectDir
1716
import kotlinx.coroutines.launch
17+
import cc.unitmesh.devti.AutoDevIcons
18+
import com.intellij.openapi.actionSystem.Presentation
1819

1920
class DomainDictGenerateAction : AnAction() {
2021
init {
@@ -23,6 +24,8 @@ class DomainDictGenerateAction : AnAction() {
2324

2425
override fun actionPerformed(event: AnActionEvent) {
2526
val project = event.project ?: return
27+
val presentation = event.presentation
28+
2629
AutoDevCoroutineScope.scope(project).launch {
2730
val names = LangDictProvider.all(project)
2831

@@ -33,10 +36,10 @@ class DomainDictGenerateAction : AnAction() {
3336
val prompt = templateRender.renderTemplate(template, context)
3437

3538
try {
36-
this@DomainDictGenerateAction.templatePresentation.icon = AutoDevIcons.InProgress
37-
this@DomainDictGenerateAction.templatePresentation.isEnabled = false
38-
val result = StringBuilder()
39+
updatePresentation(presentation, AutoDevIcons.InProgress, false)
3940
AutoDevStatusService.notifyApplication(AutoDevStatus.InProgress)
41+
42+
val result = StringBuilder()
4043
LlmFactory.create(project).stream(prompt, "").collect {
4144
result.append(it)
4245
}
@@ -53,13 +56,18 @@ class DomainDictGenerateAction : AnAction() {
5356
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
5457
e.printStackTrace()
5558
} 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)
5861
}
5962
}
6063
}
64+
65+
private fun updatePresentation(presentation: Presentation, icon: javax.swing.Icon, enabled: Boolean) {
66+
presentation.icon = icon
67+
presentation.isEnabled = enabled
68+
}
6169
}
6270

6371
data class DomainDictGenerateContext(
6472
val code: String
65-
) : TemplateContext
73+
) : TemplateContext

core/src/main/resources/genius/zh/code/indexer.vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- 它不是公共的库 API(如 Spring 等标准库或者平台的 API)、三方库 API(如 OkHttp、Retrofit 等),也不是常用的类名(如 List、Map 等)
44
- 它是关键业务概念、无法理解的单词或者拼音缩写
55
- 代码翻译中,不包含任何技术词汇,比如:Controller、Exception、Set、Code、Service、Repository、Mapper、DTO、VO、PO 等
6+
- 通用测试类和工具类(如 MathHelper)不应该被包含在内
67

78
你的返回格式:
89

java/src/main/kotlin/cc/unitmesh/idea/indexer/provider/JavaLangDictProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ class JavaLangDictProvider : LangDictProvider {
1414
FileTypeIndex.getFiles(JavaFileType.INSTANCE, searchScope)
1515
}
1616

17-
return javaFiles.mapNotNull {
17+
val filenames = javaFiles.mapNotNull {
1818
it.nameWithoutExtension
1919
}
20+
21+
return filenames
2022
}
2123
}

0 commit comments

Comments
 (0)