Skip to content

Commit

Permalink
fix: fix chat panel crash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 3, 2024
1 parent 5ac79b2 commit 2818699
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Expand Up @@ -3,7 +3,9 @@ package cc.unitmesh.devti.custom.team
import cc.unitmesh.cf.core.llms.LlmMsg
import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.custom.tasks.FileGenerateTask
import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.gui.sendToChatPanel
import cc.unitmesh.devti.gui.sendToChatWindow
import cc.unitmesh.devti.intentions.action.task.BaseCompletionTask
import cc.unitmesh.devti.intentions.action.task.CodeCompletionRequest
import com.intellij.openapi.application.runReadAction
Expand Down Expand Up @@ -32,7 +34,7 @@ class TeamPromptExecTask(

when (intentionConfig.actionPrompt.interaction) {
InteractionType.ChatPanel -> {
sendToChatPanel(project) { panel, service ->
sendToChatWindow(project, ChatActionType.CHAT) { panel, service ->
service.handleMsgsAndResponse(panel, msgs)
}
}
Expand Down
Expand Up @@ -5,6 +5,7 @@ import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
import cc.unitmesh.devti.gui.chat.ChatCodingService
import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
Expand All @@ -23,7 +24,10 @@ class AutoDevToolWindowFactory : ToolWindowFactory, DumbAware {
val content =
ContentFactory.getInstance()
.createContent(contentPanel, AutoDevBundle.message("autodev.chat"), false)
toolWindow.contentManager.addContent(content)

ApplicationManager.getApplication().invokeLater {
toolWindow.contentManager.addContent(content)
}
}

override fun init(toolWindow: ToolWindow) {
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/cc/unitmesh/devti/gui/SendToWindow.kt
Expand Up @@ -4,6 +4,7 @@ import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
import cc.unitmesh.devti.gui.chat.ChatCodingService
import cc.unitmesh.devti.provider.ContextPrompter
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
Expand All @@ -24,11 +25,13 @@ fun sendToChatWindow(
val contentPanel = ChatCodingPanel(chatCodingService, toolWindowManager.disposable)
val content = contentManager.factory.createContent(contentPanel, chatCodingService.getLabel(), false)

contentManager.removeAllContents(true)
contentManager.addContent(content)
ApplicationManager.getApplication().invokeLater {
contentManager.removeAllContents(false)
contentManager.addContent(content)

toolWindowManager.activate {
runnable(contentPanel, chatCodingService)
toolWindowManager.activate {
runnable(contentPanel, chatCodingService)
}
}
}

Expand Down

0 comments on commit 2818699

Please sign in to comment.