Skip to content

Commit

Permalink
change capabilities request to return a JsonElement
Browse files Browse the repository at this point in the history
  • Loading branch information
yairco1990 committed Nov 16, 2023
1 parent f74e976 commit 76699fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.tabnineCommon.binary.requests.capabilities

import com.google.gson.JsonElement
import com.tabnineCommon.binary.BinaryRequest

class CapabilitiesRequest : BinaryRequest<CapabilitiesResponse> {
override fun response(): Class<CapabilitiesResponse> {
return CapabilitiesResponse::class.java
class CapabilitiesRequest : BinaryRequest<JsonElement> {
override fun response(): Class<JsonElement> {
return JsonElement::class.java
}

override fun serialize(): Any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tabnineCommon.capabilities;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
Expand Down Expand Up @@ -97,13 +99,13 @@ private void fetchCapabilitiesLoop() {
}

private void fetchCapabilities() {
final CapabilitiesResponse capabilitiesResponse =
binaryRequestFacade.executeRequest(new CapabilitiesRequest());

if (capabilitiesResponse == null) {
final JsonElement jsonResponse = binaryRequestFacade.executeRequest(new CapabilitiesRequest());
if (jsonResponse == null) {
return;
}

final CapabilitiesResponse capabilitiesResponse =
new Gson().fromJson(jsonResponse, CapabilitiesResponse.class);
if (capabilitiesResponse.getEnabledFeatures() != null) {
setCapabilities(capabilitiesResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.gson.Gson
import com.google.gson.JsonElement
import com.intellij.openapi.project.Project
import com.tabnineCommon.binary.BinaryRequestFacade
import com.tabnineCommon.binary.requests.capabilities.CapabilitiesAsJsonRequest
import com.tabnineCommon.binary.requests.capabilities.CapabilitiesRequest
import com.tabnineCommon.general.DependencyContainer

data class GetCapabilitiesResponsePayload(val enabledFeatures: Array<String>)
Expand All @@ -13,7 +13,7 @@ class GetCapabilitiesHandler(gson: Gson) : ChatMessageHandler<Unit, GetCapabilit
val binaryRequestFacade: BinaryRequestFacade = DependencyContainer.instanceOfBinaryRequestFacade()

override fun handle(payload: Unit?, project: Project): GetCapabilitiesResponsePayload {
val response = binaryRequestFacade.executeRequest(CapabilitiesAsJsonRequest())
val response = binaryRequestFacade.executeRequest(CapabilitiesRequest())
return GetCapabilitiesResponsePayload(response.asJsonObject.getAsJsonArray("enabled_features").map { it.asString }.toTypedArray())
}

Expand Down

0 comments on commit 76699fa

Please sign in to comment.