Skip to content
Merged
34 changes: 4 additions & 30 deletions src/main/kotlin/com/ronin/actions/BaseRoninAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.components.service
import com.intellij.openapi.wm.ToolWindowManager
import com.ronin.service.LLMService
import com.ronin.ui.ChatToolWindowFactory
import com.ronin.MyBundle
import com.ronin.ui.chat.ChatToolWindow


abstract class BaseRoninAction : AnAction() {
Expand All @@ -27,34 +24,11 @@

val prompt = getPrompt(selectedText)

// 1. Open the Tool Window if not open
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Ronin Chat")
toolWindow?.show {
// 2. Append User's "pseudo-command" to chat
val chatWindow = ChatToolWindowFactory.ChatToolWindow.getInstance(project)
chatWindow?.appendMessage(MyBundle.message("toolwindow.you"), prompt)

// 3. Call Service
com.intellij.openapi.application.ApplicationManager.getApplication().executeOnPooledThread {
val llmService = project.service<LLMService>()

// Gather Context
val activeFile = com.intellij.openapi.application.ReadAction.compute<String?, Throwable> {
com.intellij.openapi.fileEditor.FileEditorManager.getInstance(project).selectedTextEditor?.document?.text
}

val contextBuilder = StringBuilder()
if (activeFile != null) {
contextBuilder.append("Active File Content:\n```\n$activeFile\n```\n\n")
}

val response = llmService.sendMessage(prompt, contextBuilder.toString(), emptyList())

// Parse and apply changes (side-effect)
com.ronin.service.ResponseParser.parseAndApply(response, project)

// 4. Append Response
chatWindow?.appendMessage(MyBundle.message("toolwindow.ronin"), response)
val chatWindow = ChatToolWindow.getInstance(project)
if (chatWindow != null) {

Check notice on line 30 in src/main/kotlin/com/ronin/actions/BaseRoninAction.kt

View workflow job for this annotation

GitHub Actions / Inspect code

If-Then foldable to '?.'

Foldable if-then
chatWindow.sendMessageProgrammatically(prompt)
}
}
}
Expand Down
584 changes: 21 additions & 563 deletions src/main/kotlin/com/ronin/ui/ChatToolWindowFactory.kt

Large diffs are not rendered by default.

Loading
Loading