Skip to content

Commit a4b0d04

Browse files
committed
fix(test): add check for now writing test service #78
Add WriteTestService to AutoTestThisIntention to check if language support is available for the current file. This ensures that the intention is only available when the necessary plugin is installed.
1 parent e0260aa commit a4b0d04

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/kotlin/cc/unitmesh/devti/intentions/action/AutoTestThisIntention.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.intentions.action.base.AbstractChatIntention
55
import com.intellij.temporary.getElementToAction
66
import cc.unitmesh.devti.intentions.action.task.TestCodeGenRequest
77
import cc.unitmesh.devti.intentions.action.task.TestCodeGenTask
8+
import cc.unitmesh.devti.provider.WriteTestService
89
import com.intellij.openapi.editor.Editor
910
import com.intellij.openapi.progress.ProgressManager
1011
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
@@ -16,6 +17,12 @@ class AutoTestThisIntention : AbstractChatIntention() {
1617
override fun getText(): String = AutoDevBundle.message("intentions.chat.code.test.name")
1718
override fun getFamilyName(): String = AutoDevBundle.message("intentions.chat.code.test.family.name")
1819

20+
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
21+
val psiElement = file?.originalElement ?: return false
22+
val service = WriteTestService.context(psiElement)
23+
return service != null
24+
}
25+
1926
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
2027
if (editor == null || file == null) return
2128

src/main/kotlin/cc/unitmesh/devti/provider/WriteTestService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ abstract class WriteTestService : LazyExtensionInstance<WriteTestService>() {
111111
}
112112

113113
if (writeTestService == null) {
114-
log.warn("Could not find language support for: ${psiElement.language}, make you have the plugin installed.")
115114
return null
116115
}
117116

0 commit comments

Comments
 (0)