Skip to content

Commit 6a4db18

Browse files
committed
refactor(devins-lang): add language parameter support for parsing and verifying SQL scripts before inserting them into the editor.
1 parent 12b768b commit 6a4db18

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

exts/database/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Database Extensions
22

3+
Doc: [https://plugins.jetbrains.com/docs/intellij/data-grip-extension-point-list.html](https://plugins.jetbrains.com/docs/intellij/data-grip-extension-point-list.html)
4+
35
This directory contains extensions that are specific to a database.
46

57
- Generate SQL DDL for a database from a schema

exts/database/src/main/kotlin/cc/unitmesh/database/actions/AutoSqlAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AutoSqlAction : ChatBaseIntention() {
6161
val llmProvider = LlmFactory().create(project)
6262
val prompter = AutoSqlFlow(genSqlContext, actions, contentPanel, llmProvider)
6363

64-
val task = AutoSqlBackgroundTask(project, prompter, editor)
64+
val task = AutoSqlBackgroundTask(project, prompter, editor, file.language)
6565
ProgressManager.getInstance()
6666
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
6767
}

exts/database/src/main/kotlin/cc/unitmesh/database/flow/AutoSqlBackgroundTask.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package cc.unitmesh.database.flow
22

33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.util.parser.parseCodeFromString
5+
import com.intellij.database.console.DatabaseRunners
6+
import com.intellij.database.console.runConfiguration.DatabaseScriptRunner
7+
import com.intellij.lang.Language
58
import com.intellij.openapi.command.WriteCommandAction
69
import com.intellij.openapi.diagnostic.logger
710
import com.intellij.openapi.editor.Editor
@@ -14,7 +17,8 @@ import com.intellij.sql.psi.SqlLanguage
1417
class AutoSqlBackgroundTask(
1518
private val project: Project,
1619
private val flow: AutoSqlFlow,
17-
private val editor: Editor
20+
private val editor: Editor,
21+
val language: Language
1822
) : Task.Backgroundable(project, "Gen SQL", true) {
1923
private val logger = logger<AutoSqlBackgroundTask>()
2024

@@ -44,7 +48,7 @@ class AutoSqlBackgroundTask(
4448
// verify sql script with parser
4549
try {
4650
val sqlDefine =
47-
PsiFileFactory.getInstance(project).createFileFromText("temp.sql", SqlLanguage.INSTANCE, sqlScript)
51+
PsiFileFactory.getInstance(project).createFileFromText("temp.sql", language, sqlScript)
4852
// if there is no error, we can insert the code to editor
4953
} catch (e: Exception) {
5054
logger.error("SQL Script parse error: $e")

0 commit comments

Comments
 (0)