diff --git a/.kotlin/sessions/kotlin-compiler-5168470838710847722.salive b/.kotlin/sessions/kotlin-compiler-5168470838710847722.salive new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt index cbeb3b441..1c9412361 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt @@ -9,6 +9,7 @@ import com.intellij.openapi.util.SystemInfoRt import com.intellij.util.net.HttpConfigurable import com.intellij.util.system.CpuArch import com.sourcegraph.cody.agent.protocol.* +import com.sourcegraph.cody.agent.protocol_generated.AutocompleteResult import com.sourcegraph.cody.agent.protocol_generated.ClientCapabilities import com.sourcegraph.cody.agent.protocol_generated.ClientInfo import com.sourcegraph.cody.agent.protocol_generated.ProtocolTypeAdapters @@ -293,6 +294,11 @@ private constructor( // conversions .registerTypeAdapter(URI::class.java, uriDeserializer) .registerTypeAdapter(URI::class.java, uriSerializer) + // The agent sends a badly initialized completionEvent + // that is redundant for JetBrains client. The custom deserializer + // simply ignores that field so we get no parsing errors. + .registerTypeAdapter( + AutocompleteResult::class.java, autocompleteResultDeserializer) ProtocolTypeAdapters.register(gsonBuilder) // This ensures that by default all enums are always serialized to their string diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/AutocompleteResultUtils.kt b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/AutocompleteResultUtils.kt new file mode 100644 index 000000000..2cebab948 --- /dev/null +++ b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/AutocompleteResultUtils.kt @@ -0,0 +1,25 @@ +package com.sourcegraph.cody.agent.protocol + +import com.google.gson.GsonBuilder +import com.google.gson.JsonDeserializationContext +import com.google.gson.JsonDeserializer +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import com.sourcegraph.cody.agent.protocol_generated.AutocompleteResult +import java.lang.reflect.Type + +private val gson = GsonBuilder().create() + +val autocompleteResultDeserializer = + JsonDeserializer { jsonElement: JsonElement?, _: Type, _: JsonDeserializationContext -> + val j = jsonElement?.asJsonObject + if (j == null || j.isJsonNull) { + null + } else if (j.isJsonPrimitive) { + j.asString + } else { + val obj = JsonObject() + obj.add("items", j["items"]) + gson.fromJson(obj, AutocompleteResult::class.java) + } + }