Skip to content

Commit

Permalink
chore: init for runnerbar action
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 18, 2024
1 parent c8e6071 commit 83cf83f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/233/main/resources/META-INF/autodev-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@
<add-to-group group-id="ConsoleEditorPopupMenu" anchor="first"/>
</action>

<!-- <action id="runnerBar.FixAction"-->
<!-- class="cc.unitmesh.devti.actions.run.RunPanelFixAction"-->
<!-- description="Ask AI fix error in tool bar"-->
<!-- icon="cc.unitmesh.devti.AutoDevIcons.AI_COPILOT">-->

<!-- <add-to-group group-id="RunTab.TopToolbar" anchor="first"/>-->
<!-- </action>-->

<action id="autodev.Vcs.CommitMessage"
class="cc.unitmesh.devti.actions.vcs.CommitMessageSuggestionAction"
icon="cc.unitmesh.devti.AutoDevIcons.AI_COPILOT"
Expand Down
40 changes: 40 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/actions/run/RunPanelFixAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cc.unitmesh.devti.actions.run

import cc.unitmesh.devti.AutoDevNotifications
import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.gui.sendToChatWindow
import cc.unitmesh.devti.provider.ContextPrompter
import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.execution.ui.RunContentManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent

class RunPanelFixAction : AnAction() {
fun getActionType(): ChatActionType = ChatActionType.FIX_ISSUE

override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

val selectedContent: RunContentDescriptor = RunContentManager.getInstance(project).selectedContent ?: return
val console = selectedContent?.executionConsole as ConsoleView

val sb = StringBuilder()
console.addMessageFilter { line, _ ->
sb.append(line)
null
}

val content = sb.toString()
if (content.isNotEmpty()) {
sendToChatWindow(project, getActionType()) { panel, service ->
service.handlePromptAndResponse(panel, object : ContextPrompter() {
override fun displayPrompt(): String = content
override fun requestPrompt(): String = content
}, null, true)
}
} else {
AutoDevNotifications.error(project, "Cannot extract text from run panel.");
}
}
}

0 comments on commit 83cf83f

Please sign in to comment.