Skip to content

Commit

Permalink
DEV2-4127: switch to a new thread in the jcef handler (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
yairco1990 authored Nov 9, 2023
1 parent 7ba3fbf commit e869fce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Common/src/main/java/com/tabnineCommon/chat/ChatBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.util.io.readText
import com.intellij.util.net.HttpConfigurable
import com.jetbrains.cef.JCefAppConfig
import com.tabnineCommon.general.StaticConfig
import com.tabnineCommon.general.Utils.executeThread
import org.cef.browser.CefBrowser
import org.cef.browser.CefFrame
import org.cef.handler.CefLoadHandler
Expand Down Expand Up @@ -46,7 +47,7 @@ class ChatBrowser private constructor(project: Project) {
val postMessageListener = JBCefJSQuery.create(browser)
val copyCodeListener = JBCefJSQuery.create(browser)
postMessageListener.addHandler {
handleIncomingMessage(it, project, browser)
executeThread { handleIncomingMessage(it, project, browser) }
return@addHandler null
}
copyCodeListener.addHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package com.tabnineCommon.chat.commandHandlers

import com.google.gson.Gson
import com.google.gson.JsonElement
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.project.Project
import com.tabnineCommon.chat.commandHandlers.utils.ActionPermissions
import com.tabnineCommon.chat.commandHandlers.utils.AsyncAction
Expand All @@ -18,12 +17,10 @@ abstract class ChatMessageHandler<RequestPayload, ResponsePayload>(protected val
}

protected fun getEditorFromProject(project: Project): Editor? {
return AsyncAction(ActionPermissions.WRITE).execute {
return AsyncAction(ActionPermissions.READ).execute {
try {
val fileEditor = FileEditorManager.getInstance(project).selectedEditor ?: return@execute null
val dataContext = DataManager.getInstance().getDataContext(fileEditor.component)

CommonDataKeys.EDITOR.getData(dataContext)
val fileEditor = FileEditorManager.getInstance(project).selectedEditor as? TextEditor
return@execute fileEditor?.editor
} catch (e: Exception) {
Logger.getInstance(javaClass).error("Failed to get editor from project: ", e)
null
Expand Down

0 comments on commit e869fce

Please sign in to comment.