generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/cc/unitmesh/devti/actions/run/RunPanelFixAction.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,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."); | ||
} | ||
} | ||
} |