Skip to content

Commit

Permalink
DEV2-3857: get_server_url implementation (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
Assaf Sapir authored Oct 3, 2023
1 parent 4e54965 commit 53abc37
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.gson.JsonElement
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.tabnineCommon.chat.commandHandlers.ChatMessageHandler
import com.tabnineCommon.chat.commandHandlers.GetServerUrlHandler
import com.tabnineCommon.chat.commandHandlers.GetUserHandler
import com.tabnineCommon.chat.commandHandlers.SendEventHandler
import com.tabnineCommon.chat.commandHandlers.chatSettings.GetChatSettingsHandler
Expand Down Expand Up @@ -36,6 +37,7 @@ class ChatMessagesRouter {
"insert_at_cursor" to InsertAtCursorHandler(gson),
"get_settings" to GetChatSettingsHandler(gson),
"update_settings" to UpdateChatSettingsHandler(gson),
"get_server_url" to GetServerUrlHandler(gson),
)

fun handleRawMessage(rawRequest: String, project: Project): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tabnineCommon.chat.commandHandlers

import com.google.gson.Gson
import com.google.gson.JsonElement
import com.intellij.openapi.project.Project
import com.tabnineCommon.chat.commandHandlers.utils.getServerUrl

data class ServerUrlResponse(val serverUrl: String)

class GetServerUrlHandler(gson: Gson) : ChatMessageHandler<Unit, ServerUrlResponse>(gson) {
override fun handle(payload: Unit?, project: Project): ServerUrlResponse {
val serverUrl = getServerUrl() ?: "https://api.tabnine.com"
return ServerUrlResponse(serverUrl)
}

override fun deserializeRequest(data: JsonElement?) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import com.intellij.openapi.project.Project
import com.tabnineCommon.capabilities.CapabilitiesService
import com.tabnineCommon.capabilities.Capability
import com.tabnineCommon.chat.commandHandlers.ChatMessageHandler
import com.tabnineCommon.config.Config
import com.tabnineCommon.general.StaticConfig
import com.tabnineCommon.chat.commandHandlers.utils.getServerUrl
import java.awt.Color
import javax.swing.UIManager

Expand All @@ -33,11 +32,6 @@ class InitHandler(gson: Gson) : ChatMessageHandler<Unit, InitPayload>(gson) {
return CapabilitiesService.getInstance().isCapabilityEnabled(Capability.ALPHA)
}

private fun getServerUrl(): String? {
if (!Config.IS_SELF_HOSTED) return null
return StaticConfig.getTabnineEnterpriseHost().orElse(null)
}

private fun readColorPalette(): MutableMap<String, String> {
val colorPalette = mutableMapOf<String, String>()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tabnineCommon.chat.commandHandlers.utils

import com.tabnineCommon.config.Config
import com.tabnineCommon.general.StaticConfig

fun getServerUrl(): String? {
if (!Config.IS_SELF_HOSTED) return null
return StaticConfig.getTabnineEnterpriseHost().orElse(null)
}

0 comments on commit 53abc37

Please sign in to comment.