Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.github.continuedev.continueintellijextension.browser

import com.github.continuedev.continueintellijextension.constants.MessageTypes
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.github.continuedev.continueintellijextension.services.GsonService
import com.github.continuedev.continueintellijextension.utils.uuid
import com.google.gson.Gson
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
Expand All @@ -15,7 +15,10 @@ import org.cef.browser.CefBrowser
import org.cef.handler.CefLoadHandlerAdapter
import javax.swing.JComponent

class ContinueBrowser(private val project: Project): Disposable {
class ContinueBrowser(
private val project: Project,
private val gsonService: GsonService = service<GsonService>(),
): Disposable {

private val log = Logger.getInstance(ContinueBrowser::class.java.simpleName)
private val browser: JBCefBrowser = JBCefBrowser.createBuilder().setOffScreenRendering(true).build()
Expand All @@ -25,7 +28,7 @@ class ContinueBrowser(private val project: Project): Disposable {
CefApp.getInstance().registerSchemeHandlerFactory("http", "continue", CustomSchemeHandlerFactory())
browser.jbCefClient.setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 200)
myJSQueryOpenInBrowser.addHandler { msg: String? ->
val json = Gson().fromJson(msg, BrowserMessage::class.java)
val json = gsonService.gson.fromJson(msg, BrowserMessage::class.java)
val messageType = json.messageType
val data = json.data
val messageId = json.messageId
Expand Down Expand Up @@ -82,7 +85,7 @@ class ContinueBrowser(private val project: Project): Disposable {
}

fun sendToWebview(messageType: String, data: Any? = null, messageId: String = uuid()) {
val json = Gson().toJson(BrowserMessage(messageType, messageId, data))
val json = gsonService.gson.toJson(BrowserMessage(messageType, messageId, data))
val jsCode = """window.postMessage($json, "*");"""
try {
browser.executeJavaScriptAsync(jsCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.github.continuedev.continueintellijextension.`continue`.process.Conti
import com.github.continuedev.continueintellijextension.`continue`.process.ContinueProcessHandler
import com.github.continuedev.continueintellijextension.`continue`.process.ContinueSocketProcess
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.github.continuedev.continueintellijextension.services.GsonService
import com.github.continuedev.continueintellijextension.utils.uuid
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
Expand All @@ -18,9 +18,10 @@ class CoreMessenger(
private val project: Project,
private val ideProtocolClient: IdeProtocolClient,
val coroutineScope: CoroutineScope,
private val onUnexpectedExit: () -> Unit
private val onUnexpectedExit: () -> Unit,
private val gsonService: GsonService = service<GsonService>(),
) {
private val gson = Gson()
private val gson = gsonService.gson
private val responseListeners = mutableMapOf<String, (Any?) -> Unit>()
private var process = startContinueProcess()
private val log = Logger.getInstance(CoreMessenger::class.java.simpleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.github.continuedev.continueintellijextension.error.ContinueSentryServ
import com.github.continuedev.continueintellijextension.protocol.*
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.github.continuedev.continueintellijextension.services.GsonService
import com.github.continuedev.continueintellijextension.utils.getMachineUniqueID
import com.github.continuedev.continueintellijextension.utils.uuid
import com.google.gson.Gson
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.service
Expand All @@ -34,7 +34,8 @@ import java.awt.datatransfer.StringSelection
class IdeProtocolClient(
private val continuePluginService: ContinuePluginService,
private val coroutineScope: CoroutineScope,
private val project: Project
private val project: Project,
private val gsonService: GsonService = service<GsonService>(),
) : DumbAware {
private val ide: IDE = IntelliJIDE(project, continuePluginService)
private val diffStreamService = project.service<DiffStreamService>()
Expand All @@ -51,7 +52,7 @@ class IdeProtocolClient(

fun handleMessage(msg: String, respond: (Any?) -> Unit) {
coroutineScope.launch(limitedDispatcher) {
val message = Gson().fromJson(msg, Message::class.java)
val message = gsonService.gson.fromJson(msg, Message::class.java)
val messageType = message.messageType
val dataElement = message.data

Expand Down Expand Up @@ -85,7 +86,7 @@ class IdeProtocolClient(
}

"showFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ShowFilePayload::class.java
)
Expand All @@ -99,7 +100,7 @@ class IdeProtocolClient(
}

"getControlPlaneSessionInfo" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetControlPlaneSessionInfoParams::class.java
)
Expand Down Expand Up @@ -132,7 +133,7 @@ class IdeProtocolClient(
}

"copyText" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
CopyTextParams::class.java
)
Expand All @@ -144,7 +145,7 @@ class IdeProtocolClient(
}

"showDiff" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ShowDiffParams::class.java
)
Expand All @@ -153,7 +154,7 @@ class IdeProtocolClient(
}

"readFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ReadFileParams::class.java
)
Expand All @@ -167,7 +168,7 @@ class IdeProtocolClient(
}

"readRangeInFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ReadRangeInFileParams::class.java
)
Expand All @@ -181,7 +182,7 @@ class IdeProtocolClient(
}

"getTags" -> {
val artifactId = Gson().fromJson(
val artifactId = gsonService.gson.fromJson(
dataElement.toString(),
getTagsParams::class.java
)
Expand All @@ -200,7 +201,7 @@ class IdeProtocolClient(
}

"saveFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
SaveFileParams::class.java
)
Expand All @@ -209,7 +210,7 @@ class IdeProtocolClient(
}

"showVirtualFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ShowVirtualFileParams::class.java
)
Expand All @@ -218,7 +219,7 @@ class IdeProtocolClient(
}

"showLines" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ShowLinesParams::class.java
)
Expand All @@ -227,7 +228,7 @@ class IdeProtocolClient(
}

"getFileStats" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetFileStatsParams::class.java
)
Expand All @@ -236,7 +237,7 @@ class IdeProtocolClient(
}

"listDir" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ListDirParams::class.java
)
Expand All @@ -247,7 +248,7 @@ class IdeProtocolClient(
}

"getGitRootPath" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetGitRootPathParams::class.java
)
Expand All @@ -256,7 +257,7 @@ class IdeProtocolClient(
}

"getBranch" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetBranchParams::class.java
)
Expand All @@ -265,7 +266,7 @@ class IdeProtocolClient(
}

"getRepoName" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetRepoNameParams::class.java
)
Expand All @@ -274,7 +275,7 @@ class IdeProtocolClient(
}

"getDiff" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetDiffParams::class.java
)
Expand All @@ -288,7 +289,7 @@ class IdeProtocolClient(
}

"writeFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
WriteFileParams::class.java
)
Expand All @@ -297,7 +298,7 @@ class IdeProtocolClient(
}

"fileExists" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
FileExistsParams::class.java
)
Expand All @@ -306,7 +307,7 @@ class IdeProtocolClient(
}

"openFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
OpenFileParams::class.java
)
Expand All @@ -315,7 +316,7 @@ class IdeProtocolClient(
}

"runCommand" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
RunCommandParams::class.java
)
Expand Down Expand Up @@ -353,7 +354,7 @@ class IdeProtocolClient(
}

"getSearchResults" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetSearchResultsParams::class.java
)
Expand All @@ -362,7 +363,7 @@ class IdeProtocolClient(
}

"getFileResults" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
GetFileResultsParams::class.java
)
Expand All @@ -386,7 +387,7 @@ class IdeProtocolClient(
}

"openUrl" -> {
val url = Gson().fromJson(
val url = gsonService.gson.fromJson(
dataElement.toString(),
OpenUrlParam::class.java
)
Expand All @@ -395,7 +396,7 @@ class IdeProtocolClient(
}

"insertAtCursor" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
InsertAtCursorParams::class.java
)
Expand All @@ -415,7 +416,7 @@ class IdeProtocolClient(
}

"acceptDiff" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
AcceptOrRejectDiffPayload::class.java
)
Expand All @@ -431,7 +432,7 @@ class IdeProtocolClient(
}

"rejectDiff" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
AcceptOrRejectDiffPayload::class.java
)
Expand All @@ -446,7 +447,7 @@ class IdeProtocolClient(
}

"applyToFile" -> {
val params = Gson().fromJson(
val params = gsonService.gson.fromJson(
dataElement.toString(),
ApplyToFileParams::class.java
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.continuedev.continueintellijextension.services

import com.google.gson.Gson
import com.intellij.openapi.components.Service

@Service(Service.Level.APP)
class GsonService {
val gson: Gson = Gson()
}
Loading