From 4200e789313a916e9f1c5ee57ceb7efab0898fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kondratek?= Date: Tue, 12 Nov 2024 23:05:28 +0100 Subject: [PATCH] Remove legacy CodyAgentServer --- .../com/sourcegraph/cody/agent/CodyAgent.kt | 1 + .../sourcegraph/cody/agent/CodyAgentServer.kt | 181 ------------------ .../cody/agent/ProtocolCompatibilityTest.kt | 40 ---- 3 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt delete mode 100644 src/test/kotlin/com/sourcegraph/cody/agent/ProtocolCompatibilityTest.kt diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt index bb2ab264d2..9a04bde36d 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt @@ -12,6 +12,7 @@ import com.sourcegraph.cody.agent.protocol.* import com.sourcegraph.cody.agent.protocol_extensions.ProtocolTextDocumentExt import com.sourcegraph.cody.agent.protocol_generated.ClientCapabilities import com.sourcegraph.cody.agent.protocol_generated.ClientInfo +import com.sourcegraph.cody.agent.protocol_generated.CodyAgentServer import com.sourcegraph.cody.agent.protocol_generated.ProtocolTypeAdapters import com.sourcegraph.cody.agent.protocol_generated.WebviewNativeConfig import com.sourcegraph.cody.ui.web.WebUIServiceWebviewProvider diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt deleted file mode 100644 index ad09de1d6c..0000000000 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt +++ /dev/null @@ -1,181 +0,0 @@ -@file:Suppress("FunctionName", "REDUNDANT_NULLABLE") - -package com.sourcegraph.cody.agent - -import com.sourcegraph.cody.agent.protocol_generated.AutocompleteParams -import com.sourcegraph.cody.agent.protocol_generated.AutocompleteResult -import com.sourcegraph.cody.agent.protocol_generated.Chat_ImportParams -import com.sourcegraph.cody.agent.protocol_generated.Chat_ModelsParams -import com.sourcegraph.cody.agent.protocol_generated.Chat_ModelsResult -import com.sourcegraph.cody.agent.protocol_generated.Chat_Web_NewResult -import com.sourcegraph.cody.agent.protocol_generated.ClientInfo -import com.sourcegraph.cody.agent.protocol_generated.CodeActions_ProvideParams -import com.sourcegraph.cody.agent.protocol_generated.CodeActions_ProvideResult -import com.sourcegraph.cody.agent.protocol_generated.CodeActions_TriggerParams -import com.sourcegraph.cody.agent.protocol_generated.Commands_CustomParams -import com.sourcegraph.cody.agent.protocol_generated.ContextFilters -import com.sourcegraph.cody.agent.protocol_generated.CurrentUserCodySubscription -import com.sourcegraph.cody.agent.protocol_generated.CustomCommandResult -import com.sourcegraph.cody.agent.protocol_generated.Diagnostics_PublishParams -import com.sourcegraph.cody.agent.protocol_generated.EditCommands_CodeParams -import com.sourcegraph.cody.agent.protocol_generated.EditTask -import com.sourcegraph.cody.agent.protocol_generated.EditTask_AcceptParams -import com.sourcegraph.cody.agent.protocol_generated.EditTask_CancelParams -import com.sourcegraph.cody.agent.protocol_generated.EditTask_GetTaskDetailsParams -import com.sourcegraph.cody.agent.protocol_generated.EditTask_RetryParams -import com.sourcegraph.cody.agent.protocol_generated.EditTask_UndoParams -import com.sourcegraph.cody.agent.protocol_generated.ExecuteCommandParams -import com.sourcegraph.cody.agent.protocol_generated.ExtensionConfiguration -import com.sourcegraph.cody.agent.protocol_generated.FeatureFlags_GetFeatureFlagParams -import com.sourcegraph.cody.agent.protocol_generated.Ignore_TestParams -import com.sourcegraph.cody.agent.protocol_generated.Ignore_TestResult -import com.sourcegraph.cody.agent.protocol_generated.Null -import com.sourcegraph.cody.agent.protocol_generated.ProtocolAuthStatus -import com.sourcegraph.cody.agent.protocol_generated.ProtocolTextDocument -import com.sourcegraph.cody.agent.protocol_generated.ServerInfo -import com.sourcegraph.cody.agent.protocol_generated.Testing_RequestErrorsResult -import com.sourcegraph.cody.agent.protocol_generated.TextDocument_DidFocusParams -import com.sourcegraph.cody.agent.protocol_generated.Webview_DidDisposeNativeParams -import com.sourcegraph.cody.agent.protocol_generated.Webview_ReceiveMessageStringEncodedParams -import com.sourcegraph.cody.agent.protocol_generated.Webview_ResolveWebviewViewParams -import com.sourcegraph.cody.agent.protocol_generated.Window_DidChangeFocusParams -import java.util.concurrent.CompletableFuture -import org.eclipse.lsp4j.jsonrpc.services.JsonNotification -import org.eclipse.lsp4j.jsonrpc.services.JsonRequest - -interface CodyAgentServer : _SubsetGeneratedCodyAgentServer - -// This is subset of the generated protocol bindings. -// This is only temporary until all legacy bindings are made redundant. -// Make sure to copy from the generated bindings verbatim! -interface _SubsetGeneratedCodyAgentServer { - // ======== - // Requests - // ======== - @JsonRequest("initialize") fun initialize(params: ClientInfo): CompletableFuture - - @JsonRequest("shutdown") fun shutdown(params: Null?): CompletableFuture - - @JsonRequest("autocomplete/execute") - fun autocomplete_execute(params: AutocompleteParams): CompletableFuture - - @JsonRequest("editTask/retry") - fun editTask_retry(params: EditTask_RetryParams): CompletableFuture - - @JsonRequest("editTask/getTaskDetails") - fun editTask_getTaskDetails(params: EditTask_GetTaskDetailsParams): CompletableFuture - - @JsonRequest("diagnostics/publish") - fun diagnostics_publish(params: Diagnostics_PublishParams): CompletableFuture - - @JsonRequest("command/execute") - fun command_execute(params: ExecuteCommandParams): CompletableFuture - - @JsonRequest("commands/custom") - fun commands_custom(params: Commands_CustomParams): CompletableFuture - - @JsonRequest("codeActions/provide") - fun codeActions_provide( - params: CodeActions_ProvideParams - ): CompletableFuture - - @JsonRequest("codeActions/trigger") - fun codeActions_trigger(params: CodeActions_TriggerParams): CompletableFuture - - @JsonRequest("chat/import") fun chat_import(params: Chat_ImportParams): CompletableFuture - - @JsonRequest("chat/models") - fun chat_models(params: Chat_ModelsParams): CompletableFuture - - @JsonRequest("extensionConfiguration/getSettingsSchema") - fun extensionConfiguration_getSettingsSchema(params: Null?): CompletableFuture - - @JsonRequest("extensionConfiguration/change") - fun extensionConfiguration_change( - params: ExtensionConfiguration - ): CompletableFuture - - @JsonRequest("featureFlags/getFeatureFlag") - fun featureFlags_getFeatureFlag( - params: FeatureFlags_GetFeatureFlagParams - ): CompletableFuture - - @JsonRequest("graphql/getCurrentUserCodySubscription") - fun graphql_getCurrentUserCodySubscription( - params: Null? - ): CompletableFuture - - @JsonRequest("editTask/accept") - fun editTask_accept(params: EditTask_AcceptParams): CompletableFuture - - @JsonRequest("editTask/undo") - fun editTask_undo(params: EditTask_UndoParams): CompletableFuture - - @JsonRequest("editTask/cancel") - fun editTask_cancel(params: EditTask_CancelParams): CompletableFuture - - @JsonRequest("editCommands/code") - fun editCommands_code(params: EditCommands_CodeParams): CompletableFuture - - @JsonRequest("webview/resolveWebviewView") - fun webview_resolveWebviewView(params: Webview_ResolveWebviewViewParams): CompletableFuture - - @JsonRequest("webview/receiveMessageStringEncoded") - fun webview_receiveMessageStringEncoded( - params: Webview_ReceiveMessageStringEncodedParams - ): CompletableFuture - - @JsonRequest("chat/web/new") - fun chat_web_new(params: Null?): CompletableFuture - - @JsonRequest("ignore/test") - fun ignore_test(params: Ignore_TestParams): CompletableFuture - - @JsonRequest("testing/ignore/overridePolicy") - fun testing_ignore_overridePolicy(params: ContextFilters?): CompletableFuture - - @JsonRequest("testing/requestErrors") - fun testing_requestErrors(params: Null?): CompletableFuture - - @JsonRequest("telemetry/recordEvent") - fun telemetry_recordEvent( - params: com.sourcegraph.cody.agent.protocol_generated.TelemetryEvent - ): CompletableFuture - - // // ============= - // // Notifications - // // ============= - - @JsonNotification("initialized") fun initialized(params: Null?) - - @JsonNotification("exit") fun exit(params: Null?) - - @JsonNotification("autocomplete/clearLastCandidate") - fun autocomplete_clearLastCandidate(params: Null?) - - @JsonNotification("autocomplete/completionSuggested") - fun autocomplete_completionSuggested( - params: com.sourcegraph.cody.agent.protocol_generated.CompletionItemParams - ) - - @JsonNotification("autocomplete/completionAccepted") - fun autocomplete_completionAccepted( - params: com.sourcegraph.cody.agent.protocol_generated.CompletionItemParams - ) - - @JsonNotification("textDocument/didOpen") fun textDocument_didOpen(params: ProtocolTextDocument) - - @JsonNotification("textDocument/didChange") - fun textDocument_didChange(params: ProtocolTextDocument) - - @JsonNotification("textDocument/didFocus") - fun textDocument_didFocus(params: TextDocument_DidFocusParams) - - @JsonNotification("textDocument/didClose") fun textDocument_didClose(params: ProtocolTextDocument) - - @JsonNotification("window/didChangeFocus") - fun window_didChangeFocus(params: Window_DidChangeFocusParams) - - @JsonNotification("webview/didDisposeNative") - fun webview_didDisposeNative(params: Webview_DidDisposeNativeParams) -} diff --git a/src/test/kotlin/com/sourcegraph/cody/agent/ProtocolCompatibilityTest.kt b/src/test/kotlin/com/sourcegraph/cody/agent/ProtocolCompatibilityTest.kt deleted file mode 100644 index 5b8d7270ac..0000000000 --- a/src/test/kotlin/com/sourcegraph/cody/agent/ProtocolCompatibilityTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.sourcegraph.cody.agent - -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import com.sourcegraph.cody.agent.protocol_generated.CodyAgentServer as TargetCodyAgentServer -import kotlin.reflect.full.declaredFunctions -import kotlin.test.assertTrue -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -@RunWith(JUnit4::class) -class ProtocolCompatibilityTest : BasePlatformTestCase() { - /** - * I verified this works by altering one of the copied methods. interface - * com.sourcegraph.cody.agent._SubsetGeneratedCodyAgentServer is not a subset of interface - * com.sourcegraph.cody.agent.protocol_generated.CodyAgentServer. Incompatible methods: - * (graphql_currentUserId, [kotlin.String]) This ensures we make no changes to the protocol while - * we're still subsetting generated protocol methods. - */ - private fun assertSubsetInterface(superInterface: Class<*>, subInterface: Class<*>) { - val superMethods = - superInterface.kotlin.declaredFunctions - .map { it.name to it.parameters.drop(1).map { param -> param.type } } - .toSet() - val subMethods = - subInterface.kotlin.declaredFunctions - .map { it.name to it.parameters.drop(1).map { param -> param.type } } - .toSet() - - assertTrue( - subMethods.all { it in superMethods }, - "$subInterface is not a subset of $superInterface. Incompatible methods: \n${(subMethods - superMethods).joinToString("\n")}") - } - - @Test - fun `copies generated protocol verbatim`() { - assertSubsetInterface( - TargetCodyAgentServer::class.java, _SubsetGeneratedCodyAgentServer::class.java) - } -}