Skip to content

Commit

Permalink
refactor(actions): remove RunPanelFixAction and refactor FixThisAction
Browse files Browse the repository at this point in the history
…#329

- Delete unused RunPanelFixAction file.
- Refactor FixThisAction to use TemplateRender for error prompts.
- Introduce ErrorContext for template rendering.
  • Loading branch information
phodal committed Mar 10, 2025
1 parent bdcc7a4 commit 5d73d34
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import cc.unitmesh.devti.gui.sendToChatWindow
import cc.unitmesh.devti.prompting.TextTemplatePrompt
import cc.unitmesh.devti.provider.ContextPrompter
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback.presentationText
import cc.unitmesh.devti.template.GENIUS_ERROR
import cc.unitmesh.devti.template.TemplateRender
import cc.unitmesh.devti.template.context.TemplateContext
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.diagnostic.logger
import com.intellij.temporary.error.ErrorPromptBuilder


class FixThisAction : ChatBaseAction() {
init {
Expand All @@ -28,7 +29,7 @@ class FixThisAction : ChatBaseAction() {
val selectionModel = editor.selectionModel
val text = selectionModel.selectedText ?: return

prompt = ErrorPromptBuilder.buildDisplayPrompt(text, text, "Fix this")
prompt = buildDisplayPrompt(text, text, "Fix this")

if (prompt.displayText.isBlank() || prompt.requestText.isBlank()) {
logger.error("Prompt is null, description: $text")
Expand All @@ -42,4 +43,18 @@ class FixThisAction : ChatBaseAction() {
}, null, true)
}
}

fun buildDisplayPrompt(errorTextTrimmed: String, sourceCode: String, displayText: String): TextTemplatePrompt {
val templateRender = TemplateRender(GENIUS_ERROR)
templateRender.context = ErrorContext(errorTextTrimmed, sourceCode)
val template = templateRender.getTemplate("fix-error.vm")
val prompt = templateRender.renderTemplate(template)
return TextTemplatePrompt(displayText, prompt)
}
}

data class ErrorContext(
val errorText: String,
val sourceCode: String,
) : TemplateContext

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.intellij.openapi.project.DumbAware
* @author lk
*/
class AutoChatDynamicActionGroup : DefaultActionGroup(), DumbAware {

init {
presentationText("autodev.chat", templatePresentation.also { it.isHideGroupIfEmpty = true }, 1)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class NormalChatCodingPanel(private val chatCodingService: ChatCodingService, va
* passing the current text to be replaced in the editor.
*/
suspend fun updateReplaceableContent(content: Flow<String>, postAction: (text: String) -> Unit) {
myList.remove(myList.componentCount - 1)
showProgressBar()
val text = updateMessageInUi(content)

Expand Down

0 comments on commit 5d73d34

Please sign in to comment.