🚧 pass messages through to core
This commit is contained in:
parent
05b8776bd3
commit
a4b8b1c4e7
5 changed files with 26 additions and 6 deletions
|
|
@ -207,6 +207,7 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware {
|
|||
val continueCorePath = Paths.get(pluginPath.toString(), "core", "pkg").toString()
|
||||
|
||||
val coreMessenger = CoreMessenger(continueCorePath, ideProtocolClient);
|
||||
continuePluginService.coreMessenger = coreMessenger
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class CoreMessenger(continueCorePath: String, ideProtocolClient: IdeProtocolClie
|
|||
println("Subprocess exited with code: $exitCode")
|
||||
}
|
||||
|
||||
fun request(messageType: String, data: Any, onResponse: (String) -> Unit) {
|
||||
fun request(messageType: String, data: Any?, onResponse: (String) -> Unit) {
|
||||
val messageId = uuid();
|
||||
val message = gson.toJson(mapOf(
|
||||
"messageId" to messageId,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.continuedev.continueintellijextension.services
|
||||
|
||||
import com.github.continuedev.continueintellijextension.`continue`.CoreMessenger
|
||||
import com.github.continuedev.continueintellijextension.`continue`.IdeProtocolClient
|
||||
import com.github.continuedev.continueintellijextension.`continue`.uuid
|
||||
import com.github.continuedev.continueintellijextension.toolWindow.ContinuePluginToolWindowFactory
|
||||
|
|
@ -21,6 +22,7 @@ class ContinuePluginService(project: Project) : Disposable, DumbAware {
|
|||
var continuePluginWindow: ContinuePluginToolWindowFactory.ContinuePluginWindow? = null
|
||||
|
||||
var ideProtocolClient: IdeProtocolClient? = null
|
||||
var coreMessenger: CoreMessenger? = null
|
||||
var worksapcePaths: Array<String>? = null
|
||||
var windowId: String = UUID.randomUUID().toString()
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
|
||||
class ContinuePluginWindow(toolWindow: ToolWindow, project: Project) {
|
||||
|
||||
val PASS_THROUGH_TO_CORE = listOf(
|
||||
"getSerializedConfig"
|
||||
)
|
||||
|
||||
init {
|
||||
System.setProperty("ide.browser.jcef.jsQueryPoolSize", JS_QUERY_POOL_SIZE)
|
||||
}
|
||||
|
|
@ -83,8 +87,8 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
val parser = JsonParser()
|
||||
val json: JsonObject = parser.parse(msg).asJsonObject
|
||||
val messageType = json.get("messageType").asString
|
||||
val data = json.get("data").asJsonObject
|
||||
val messageId = json.get("messageId").asString
|
||||
val data = json.get("data")
|
||||
val messageId = json.get("messageId")?.asString
|
||||
|
||||
val ide = continuePluginService.ideProtocolClient;
|
||||
|
||||
|
|
@ -98,6 +102,11 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
browser.executeJavaScriptAsync("""window.postMessage($jsonString, "*");""")
|
||||
}
|
||||
|
||||
if (PASS_THROUGH_TO_CORE.contains(messageType)) {
|
||||
continuePluginService.coreMessenger?.request(messageType, data, respond)
|
||||
return@addHandler null
|
||||
}
|
||||
|
||||
when (messageType) {
|
||||
"onLoad" -> {
|
||||
GlobalScope.launch {
|
||||
|
|
@ -143,6 +152,7 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
|
||||
}
|
||||
"showLines" -> {
|
||||
val data = data.asJsonObject
|
||||
ide?.highlightCode(RangeInFile(
|
||||
data.get("filepath").asString,
|
||||
Range(Position(
|
||||
|
|
@ -156,9 +166,11 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
),"#00ff0022")
|
||||
}
|
||||
"showVirtualFile" -> {
|
||||
val data = data.asJsonObject
|
||||
ide?.showVirtualFile(data.get("name").asString, data.get("content").asString)
|
||||
}
|
||||
"showFile" -> {
|
||||
val data = data.asJsonObject
|
||||
ide?.setFileOpen(data.get("filepath").asString)
|
||||
}
|
||||
"reloadWindow" -> {}
|
||||
|
|
@ -166,6 +178,7 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
ide?.setFileOpen(getConfigJsonPath())
|
||||
}
|
||||
"readRangeInFile" -> {
|
||||
val data = data.asJsonObject
|
||||
ide?.readRangeInFile(RangeInFile(
|
||||
data.get("filepath").asString,
|
||||
Range(Position(
|
||||
|
|
@ -211,8 +224,8 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware {
|
|||
|
||||
fun executeJavaScript(browser: CefBrowser?, myJSQueryOpenInBrowser: JBCefJSQuery) {
|
||||
// Execute JavaScript - you might want to handle potential exceptions here
|
||||
val script = """window.postIntellijMessage = function(type, data) {
|
||||
const msg = JSON.stringify({type, data});
|
||||
val script = """window.postIntellijMessage = function(messageType, data, messageId) {
|
||||
const msg = JSON.stringify({messageType, data, messageId});
|
||||
${myJSQueryOpenInBrowser.inject("msg")}
|
||||
}""".trimIndent()
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ function _postToIde(messageType: string, data: any, messageId?: string) {
|
|||
);
|
||||
throw new Error("postIntellijMessage is undefined");
|
||||
}
|
||||
(window as any).postIntellijMessage?.(messageType, data);
|
||||
(window as any).postIntellijMessage?.(
|
||||
messageType,
|
||||
data,
|
||||
messageId ?? uuidv4()
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
console.log(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue