Skip to content

Commit 6669b4b

Browse files
committed
fix(java): add Java language check in AutoCrudAction
1 parent d23aa0f commit 6669b4b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

exts/database/src/main/kotlin/cc/unitmesh/database/provider/SqlLivingDocumentationProvider.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.SelectionModel
88
import com.intellij.psi.PsiElement
99
import com.intellij.psi.PsiNameIdentifierOwner
1010
import com.intellij.psi.codeStyle.CodeStyleManager
11+
import com.intellij.sql.psi.SqlDefinition
1112

1213
class SqlLivingDocumentationProvider : LivingDocumentation {
1314
override val forbiddenRules: List<String>
@@ -34,6 +35,13 @@ class SqlLivingDocumentationProvider : LivingDocumentation {
3435
}
3536

3637
override fun findNearestDocumentationTarget(psiElement: PsiElement): PsiNameIdentifierOwner? {
38+
// todo: find nearest sql definition
39+
when (psiElement) {
40+
is SqlDefinition -> {
41+
return psiElement
42+
}
43+
}
44+
3745
return null
3846
}
3947

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- sample for create blog
2+
CREATE TABLE `blog`
3+
(
4+
`id` int(11) NOT NULL AUTO_INCREMENT,
5+
`title` varchar(255) DEFAULT NULL,
6+
`content` varchar(255) DEFAULT NULL,
7+
`create_time` datetime DEFAULT NULL,
8+
`update_time` datetime DEFAULT NULL,
9+
PRIMARY KEY (`id`)
10+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

java/src/main/kotlin/cc/unitmesh/idea/actions/AutoCrudAction.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.intentions.action.base.AbstractChatIntention
55
import cc.unitmesh.devti.llms.LlmFactory
66
import cc.unitmesh.devti.provider.DevFlowProvider
77
import cc.unitmesh.devti.gui.sendToChatPanel
8+
import com.intellij.lang.java.JavaLanguage
89
import com.intellij.openapi.diagnostic.logger
910
import com.intellij.openapi.editor.Editor
1011
import com.intellij.openapi.progress.ProgressIndicator
@@ -22,8 +23,11 @@ class AutoCrudAction : AbstractChatIntention() {
2223

2324

2425
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
26+
if (editor == null || file == null) return false
27+
if (file.language !is JavaLanguage) return false
28+
2529
val isEnvironmentAvailable = super.isAvailable(project, editor, file)
26-
return isEnvironmentAvailable && editor?.selectionModel?.hasSelection() == true
30+
return isEnvironmentAvailable && editor.selectionModel?.hasSelection() == true
2731
}
2832

2933
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {

0 commit comments

Comments
 (0)