diff --git a/exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlScriptBySelection.kt b/exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlAction.kt similarity index 88% rename from exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlScriptBySelection.kt rename to exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlAction.kt index 77f36bb039..12fc76506e 100644 --- a/exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlScriptBySelection.kt +++ b/exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenSqlAction.kt @@ -1,7 +1,7 @@ package cc.unitmesh.database.actions import cc.unitmesh.database.DbContextActionProvider -import cc.unitmesh.database.flow.GenFlowContext +import cc.unitmesh.database.flow.GenSqlContext import cc.unitmesh.database.flow.GenSqlFlow import cc.unitmesh.database.flow.GenSqlTask import cc.unitmesh.devti.AutoDevBundle @@ -11,7 +11,6 @@ import cc.unitmesh.devti.llms.LlmFactory import com.intellij.database.model.ObjectKind import com.intellij.database.psi.DbPsiFacade import com.intellij.database.util.DasUtil -import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.editor.Editor import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator @@ -19,7 +18,7 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile -class GenSqlScriptBySelection : AbstractChatIntention() { +class GenSqlAction : AbstractChatIntention() { override fun priority(): Int = 1001 override fun startInWriteAction(): Boolean = false override fun getFamilyName(): String = AutoDevBundle.message("migration.database.plsql") @@ -30,8 +29,6 @@ class GenSqlScriptBySelection : AbstractChatIntention() { return true } - private val logger = logger() - override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { if (editor == null || file == null) return @@ -48,7 +45,7 @@ class GenSqlScriptBySelection : AbstractChatIntention() { tables.filter { table -> table.kind == ObjectKind.TABLE && table.dasParent?.name == schemaName } }.toList() - val genFlowContext = GenFlowContext( + val genSqlContext = GenSqlContext( requirement = selectedText ?: "", databaseVersion = databaseVersion.let { "name: ${it.name}, version: ${it.version}" @@ -61,7 +58,7 @@ class GenSqlScriptBySelection : AbstractChatIntention() { sendToChatPanel(project) { contentPanel, _ -> val llmProvider = LlmFactory().create(project) - val prompter = GenSqlFlow(genFlowContext, actions, contentPanel, llmProvider, project) + val prompter = GenSqlFlow(genSqlContext, actions, contentPanel, llmProvider, project) val task = GenSqlTask(project, prompter, editor) ProgressManager.getInstance() diff --git a/exts/database/src/main/kotlin/cc/unitmesh/database/actions/ModularDesignAction.kt b/exts/database/src/main/kotlin/cc/unitmesh/database/actions/ModularDesignAction.kt deleted file mode 100644 index 2b110ef1b4..0000000000 --- a/exts/database/src/main/kotlin/cc/unitmesh/database/actions/ModularDesignAction.kt +++ /dev/null @@ -1,25 +0,0 @@ -package cc.unitmesh.database.actions - -import cc.unitmesh.devti.AutoDevBundle -import cc.unitmesh.devti.intentions.action.base.AbstractChatIntention -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project -import com.intellij.psi.PsiFile - -class ModularDesignAction : AbstractChatIntention() { - override fun priority(): Int = 899 - - override fun startInWriteAction(): Boolean = false - - override fun getFamilyName(): String = AutoDevBundle.message("migration.database.plsql") - - override fun getText(): String = AutoDevBundle.message("migration.database.plsql.modular.design") - - override fun isAvailable(project: Project, editor: Editor?, psiFile: PsiFile?): Boolean { - return false - } - - override fun invoke(project: Project, editor: Editor?, psiFile: PsiFile?) { - TODO("Not yet implemented") - } -} diff --git a/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenFlowContext.kt b/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlContext.kt similarity index 63% rename from exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenFlowContext.kt rename to exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlContext.kt index 3973817eb1..df8d521e46 100644 --- a/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenFlowContext.kt +++ b/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlContext.kt @@ -1,10 +1,13 @@ package cc.unitmesh.database.flow -data class GenFlowContext( +data class GenSqlContext( val requirement: String, val databaseVersion: String, val schemaName: String, val tableNames: List, - // for step 2 + /** + * Step 2. + * A list of table names to retrieve the columns from. + */ var tableInfos: List = emptyList(), ) \ No newline at end of file diff --git a/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlFlow.kt b/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlFlow.kt index 35f22621dd..36216d3e3e 100644 --- a/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlFlow.kt +++ b/exts/database/src/main/kotlin/cc/unitmesh/database/flow/GenSqlFlow.kt @@ -11,7 +11,7 @@ import com.intellij.openapi.project.Project import kotlinx.coroutines.runBlocking class GenSqlFlow( - val genFlowContext: GenFlowContext, + val genSqlContext: GenSqlContext, val actions: DbContextActionProvider, val ui: ChatCodingPanel, val llm: LLMProvider, @@ -20,7 +20,7 @@ class GenSqlFlow( private val logger = logger() fun clarify(): String { - val stepOnePrompt = generateStepOnePrompt(genFlowContext, actions) + val stepOnePrompt = generateStepOnePrompt(genSqlContext, actions) LLMCoroutineScope.scope(project).runCatching { ui.addMessage(stepOnePrompt, true, stepOnePrompt) @@ -36,7 +36,7 @@ class GenSqlFlow( } fun generate(tableNames: List): String { - val stepTwoPrompt = generateStepTwoPrompt(genFlowContext, actions, tableNames) + val stepTwoPrompt = generateStepTwoPrompt(genSqlContext, actions, tableNames) LLMCoroutineScope.scope(project).runCatching { ui.addMessage(stepTwoPrompt, true, stepTwoPrompt) @@ -51,7 +51,7 @@ class GenSqlFlow( } } - private fun generateStepOnePrompt(context: GenFlowContext, actions: DbContextActionProvider): String { + private fun generateStepOnePrompt(context: GenSqlContext, actions: DbContextActionProvider): String { val templateRender = TemplateRender("genius/sql") val template = templateRender.getTemplate("sql-gen-clarify.vm") @@ -65,16 +65,16 @@ class GenSqlFlow( } private fun generateStepTwoPrompt( - genFlowContext: GenFlowContext, + genSqlContext: GenSqlContext, actions: DbContextActionProvider, tableInfos: List ): String { val templateRender = TemplateRender("genius/sql") val template = templateRender.getTemplate("sql-gen-design.vm") - genFlowContext.tableInfos = actions.getTableColumns(tableInfos) + genSqlContext.tableInfos = actions.getTableColumns(tableInfos) - templateRender.context = genFlowContext + templateRender.context = genSqlContext templateRender.actions = actions val prompter = templateRender.renderTemplate(template) diff --git a/exts/database/src/main/resources/cc.unitmesh.database.xml b/exts/database/src/main/resources/cc.unitmesh.database.xml index 0dc7b82061..537c8bde6f 100644 --- a/exts/database/src/main/resources/cc.unitmesh.database.xml +++ b/exts/database/src/main/resources/cc.unitmesh.database.xml @@ -21,12 +21,7 @@ intention.category.llm - cc.unitmesh.database.actions.GenSqlScriptBySelection - messages.AutoDevBundle - intention.category.llm - - - cc.unitmesh.database.actions.ModularDesignAction + cc.unitmesh.database.actions.GenSqlAction messages.AutoDevBundle intention.category.llm