generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): add GenerateFunctionAction for testing PL/SQL
Add a new class `GenerateFunctionAction` to the database module. This class is responsible for generating Java functions based on Oracle PL/SQL code. It includes methods for checking if the action is available, invoking the action, and rendering the template for generating the function. The class also includes a data class `GenFunctionContext` to hold the language and SQL code for the function.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenerateFunctionAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cc.unitmesh.database.actions | ||
|
||
import cc.unitmesh.devti.gui.sendToChatWindow | ||
import cc.unitmesh.devti.intentions.action.base.AbstractChatIntention | ||
import cc.unitmesh.devti.provider.ContextPrompter | ||
import cc.unitmesh.devti.template.TemplateRender | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.sql.dialects.oracle.OraDialect | ||
|
||
class GenerateFunctionAction : AbstractChatIntention() { | ||
override fun priority() = 901 | ||
|
||
override fun getFamilyName(): String = "Generate Java Function" | ||
|
||
override fun getText(): String = "Generate Java Function" | ||
|
||
val logger = logger<GenerateFunctionAction>() | ||
|
||
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean { | ||
if (editor == null || file == null) return false | ||
val isOracle = file.language is OraDialect | ||
val selectedText = editor.selectionModel | ||
val element = file.findElementAt(selectedText.selectionStart) | ||
|
||
if (element != null) { | ||
logger.info("element: ${element.text}") | ||
} | ||
|
||
return isOracle | ||
} | ||
|
||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { | ||
if (editor == null || file == null) return | ||
val selectedText = editor.selectionModel.selectedText ?: return | ||
|
||
val templateRender = TemplateRender("genius/migration") | ||
val template = templateRender.getTemplate("gen-function.vm") | ||
templateRender.context = GenFunctionContext( | ||
lang = file.language.displayName ?: "", | ||
sql = selectedText, | ||
) | ||
|
||
val prompter = templateRender.renderTemplate(template) | ||
|
||
logger.info("Prompt: $prompter") | ||
|
||
sendToChatWindow(project, getActionType()) { panel, service -> | ||
service.handlePromptAndResponse(panel, object : ContextPrompter() { | ||
override fun displayPrompt(): String = prompter | ||
override fun requestPrompt(): String = prompter | ||
}, null, false) | ||
} | ||
} | ||
|
||
} | ||
|
||
data class GenFunctionContext(val lang: String, val sql: String) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
exts/database/src/main/resources/genius/migration/gen-function.vm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
You are a professional application migration programmer. | ||
Based on the following Oracle PL/SQL code to Java function, | ||
|
||
— When some function is missing in Java, just skip it. | ||
- If you find some function is not correct, please fix it. | ||
- Follow the Java coding style. | ||
|
||
|
||
```${context.lang} | ||
${context.sql} | ||
``` | ||
|
||
|