Merge pull request #4021 from continuedev/dallin/at-files
Fix Jetbrains messaging logic
This commit is contained in:
commit
db169e484b
2 changed files with 16 additions and 22 deletions
|
|
@ -43,27 +43,12 @@ class IdeProtocolClient(
|
|||
)
|
||||
}
|
||||
|
||||
private fun send(messageType: String, data: Any?, messageId: String? = null) {
|
||||
val id = messageId ?: uuid()
|
||||
continuePluginService.sendToWebview(messageType, data, id)
|
||||
}
|
||||
|
||||
fun handleMessage(msg: String, respond: (Any?) -> Unit) {
|
||||
coroutineScope.launch(Dispatchers.IO) {
|
||||
val message = Gson().fromJson(msg, Message::class.java)
|
||||
val messageType = message.messageType
|
||||
val dataElement = message.data
|
||||
|
||||
// A couple oddball messages respond directly to GUI, expect a different message format
|
||||
// e.g. jetbrains/isOSREnabled
|
||||
fun respondToWebview(content: Any) {
|
||||
respond(mutableMapOf(
|
||||
"done" to true,
|
||||
"status" to "success",
|
||||
"content" to content
|
||||
))
|
||||
}
|
||||
|
||||
try {
|
||||
when (messageType) {
|
||||
"toggleDevTools" -> {
|
||||
|
|
@ -77,12 +62,12 @@ class IdeProtocolClient(
|
|||
"jetbrains/isOSREnabled" -> {
|
||||
val isOSREnabled =
|
||||
ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR
|
||||
respondToWebview(isOSREnabled)
|
||||
respond(isOSREnabled)
|
||||
}
|
||||
|
||||
"jetbrains/getColors" -> {
|
||||
val colors = GetTheme().getTheme();
|
||||
respondToWebview(colors)
|
||||
respond(colors)
|
||||
}
|
||||
|
||||
"jetbrains/onLoad" -> {
|
||||
|
|
@ -92,7 +77,7 @@ class IdeProtocolClient(
|
|||
"vscMachineId" to getMachineUniqueID(),
|
||||
"vscMediaUrl" to "http://continue",
|
||||
)
|
||||
respondToWebview(jsonData)
|
||||
respond(jsonData)
|
||||
}
|
||||
|
||||
"getIdeSettings" -> {
|
||||
|
|
@ -593,11 +578,11 @@ class IdeProtocolClient(
|
|||
|
||||
|
||||
fun sendAcceptRejectDiff(accepted: Boolean, stepIndex: Int) {
|
||||
send("acceptRejectDiff", AcceptRejectDiff(accepted, stepIndex), uuid())
|
||||
continuePluginService.sendToWebview("acceptRejectDiff", AcceptRejectDiff(accepted, stepIndex), uuid())
|
||||
}
|
||||
|
||||
fun deleteAtIndex(index: Int) {
|
||||
send("deleteAtIndex", DeleteAtIndex(index), uuid())
|
||||
continuePluginService.sendToWebview("deleteAtIndex", DeleteAtIndex(index), uuid())
|
||||
}
|
||||
|
||||
private fun getModelByRole(
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ class ContinueBrowser(val project: Project, url: String) {
|
|||
ContinuePluginService::class.java
|
||||
)
|
||||
|
||||
|
||||
val respond = fun(data: Any?) {
|
||||
sendToWebview(messageType, data, messageId ?: uuid())
|
||||
}
|
||||
|
|
@ -63,8 +62,18 @@ class ContinueBrowser(val project: Project, url: String) {
|
|||
return@addHandler null
|
||||
}
|
||||
|
||||
// If not pass through, then put it in the status/content/done format for webview
|
||||
// Core already sends this format
|
||||
val respondToWebview = fun(data: Any?) {
|
||||
sendToWebview(messageType, mapOf(
|
||||
"status" to "success",
|
||||
"content" to data,
|
||||
"done" to true
|
||||
), messageId ?: uuid())
|
||||
}
|
||||
|
||||
if (msg != null) {
|
||||
continuePluginService.ideProtocolClient?.handleMessage(msg, respond)
|
||||
continuePluginService.ideProtocolClient?.handleMessage(msg, respondToWebview)
|
||||
}
|
||||
|
||||
null
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue