From a016e2ee6b01b102cd50e67e520f77b7683fc5af Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Mon, 19 Aug 2024 16:59:55 +0200 Subject: [PATCH] Fixes fro review --- .../sourcegraph/cody/agent/CodyAgentClient.kt | 21 ------- .../cody/agent/CodyAgentClientTest.kt | 62 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 src/test/kotlin/com/sourcegraph/cody/agent/CodyAgentClientTest.kt diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentClient.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentClient.kt index e1ee7b485a..13a0cc3792 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentClient.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentClient.kt @@ -2,7 +2,6 @@ package com.sourcegraph.cody.agent import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runInEdt -import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project import com.sourcegraph.cody.agent.protocol.ProtocolTextDocument @@ -36,9 +35,6 @@ class CodyAgentClient(private val project: Project, private val webview: NativeW private val logger = Logger.getInstance(CodyAgentClient::class.java) } - // Callback that is invoked when the agent sends a "setConfigFeatures" message. - var onSetConfigFeatures: ConfigFeaturesObserver = project.service() - /** * Helper to run client request/notification handlers on the IntelliJ event thread. Use this * helper for handlers that require access to the IntelliJ editor, for example to read the text @@ -191,21 +187,4 @@ class CodyAgentClient(private val project: Project, private val webview: NativeW // TODO: Implement this. println("TODO, implement webview/dispose") } - - // TODO: Remove this - @JsonNotification("webview/postMessage") - fun webviewPostMessage(params: WebviewPostMessageParams) { - if (params.message.type == ExtensionMessage.Type.SET_CONFIG_FEATURES) { - runInEdt { onSetConfigFeatures.update(params.message.configFeatures) } - } - - logger.debug("webview/postMessage ${params.id}: ${params.message}") - } - - // TODO: Remove this - @JsonRequest("webview/create") - fun webviewCreate(params: WebviewCreateParams): CompletableFuture { - logger.error("webview/create This request should not happen if you are using chat/new.") - return CompletableFuture.completedFuture(null) - } } diff --git a/src/test/kotlin/com/sourcegraph/cody/agent/CodyAgentClientTest.kt b/src/test/kotlin/com/sourcegraph/cody/agent/CodyAgentClientTest.kt deleted file mode 100644 index d7c2e614f9..0000000000 --- a/src/test/kotlin/com/sourcegraph/cody/agent/CodyAgentClientTest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.sourcegraph.cody.agent - -import com.intellij.openapi.project.Project -import com.intellij.testFramework.PlatformTestUtil -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import java.util.concurrent.locks.ReentrantLock -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -@RunWith(JUnit4::class) -class CodyAgentClientTest : BasePlatformTestCase() { - companion object { - const val WEBVIEW_ID: String = "unused-webview-id" - } - - @Volatile var lastMessage: ConfigFeatures? = null - - // Use lock/condition to synchronize between observer being invoked - // and the test being able to assert. - private val lock = ReentrantLock() - private val condition = lock.newCondition() - - private fun client(project: Project): CodyAgentClient { - val client = CodyAgentClient(project, StubWebviewProvider()) - client.onSetConfigFeatures = ConfigFeaturesObserver { - lock.lock() - try { - lastMessage = it - condition.signal() - } finally { - lock.unlock() - } - } - return client - } - - @Test - fun `notifies observer`() { - val expected = ConfigFeatures(attribution = true, serverSentModels = true) - client(myFixture.project) - .webviewPostMessage( - WebviewPostMessageParams( - id = WEBVIEW_ID, - message = - ExtensionMessage( - type = ExtensionMessage.Type.SET_CONFIG_FEATURES, - errors = null, - configFeatures = expected, - ))) - PlatformTestUtil.dispatchAllEventsInIdeEventQueue() - lock.lock() - try { - if (expected != lastMessage) { - condition.await() - } - assertEquals(expected, lastMessage) - } finally { - lock.unlock() - } - } -}