diff --git a/src/main/java/com/sourcegraph/cody/CodyFileEditorListener.java b/src/main/java/com/sourcegraph/cody/CodyFileEditorListener.java index 3b976a0f26..37ba3e1cf5 100644 --- a/src/main/java/com/sourcegraph/cody/CodyFileEditorListener.java +++ b/src/main/java/com/sourcegraph/cody/CodyFileEditorListener.java @@ -33,9 +33,10 @@ public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile f } CodyAgentService.withAgent( - source.getProject(), - agent -> agent.getServer().textDocumentDidClose(ProtocolTextDocument.fromVirtualFile(file))); - } + source.getProject(), + agent -> + agent.getServer().textDocumentDidClose(ProtocolTextDocument.fromVirtualFile(file))); + } public static void fileOpened(Project project, CodyAgent codyAgent, @NotNull VirtualFile file) { Document document = @@ -43,7 +44,8 @@ public static void fileOpened(Project project, CodyAgent codyAgent, @NotNull Vir .runReadAction( (Computable) () -> FileDocumentManager.getInstance().getDocument(file)); if (document != null) { - ProtocolTextDocument textDocument = ProtocolTextDocument.fromVirtualFile(file, document.getText()); + ProtocolTextDocument textDocument = + ProtocolTextDocument.fromVirtualFile(file, document.getText()); codyAgent.getServer().textDocumentDidOpen(textDocument); } diff --git a/src/main/java/com/sourcegraph/cody/CodyFocusChangeListener.java b/src/main/java/com/sourcegraph/cody/CodyFocusChangeListener.java index 218d1dd69e..a32de2fde1 100644 --- a/src/main/java/com/sourcegraph/cody/CodyFocusChangeListener.java +++ b/src/main/java/com/sourcegraph/cody/CodyFocusChangeListener.java @@ -57,7 +57,6 @@ public void focusGained(@NotNull Editor editor) { agent.getServer().textDocumentDidFocus(ProtocolTextDocument.fromVirtualFile(file)); }); - CodyAgentCodebase.getInstance(project).onFileOpened(project, file); } } diff --git a/src/main/java/com/sourcegraph/cody/agent/CodyAgentClient.java b/src/main/java/com/sourcegraph/cody/agent/CodyAgentClient.java index 8b4f3be60c..8d79ff161b 100644 --- a/src/main/java/com/sourcegraph/cody/agent/CodyAgentClient.java +++ b/src/main/java/com/sourcegraph/cody/agent/CodyAgentClient.java @@ -69,18 +69,18 @@ public void editTaskDidUpdate(EditTask params) { }); } - @JsonNotification("editTask/didDelete") - public void editTaskDidDelete(EditTask params) { - onEventThread( - () -> { - if (onEditTaskDidDelete != null) { - onEditTaskDidDelete.accept(params); - } else { - logger.warn("No callback registered for editTask/didDelete"); - } - return null; - }); - } + @JsonNotification("editTask/didDelete") + public void editTaskDidDelete(EditTask params) { + onEventThread( + () -> { + if (onEditTaskDidDelete != null) { + onEditTaskDidDelete.accept(params); + } else { + logger.warn("No callback registered for editTask/didDelete"); + } + return null; + }); + } public void setOnTextDocumentEdit(@Nullable Consumer callback) { onTextDocumentEdit = callback; diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt index a6432bbfe6..da92bd072e 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt @@ -10,13 +10,13 @@ import com.intellij.util.system.CpuArch import com.sourcegraph.cody.agent.protocol.* import com.sourcegraph.cody.vscode.CancellationToken import com.sourcegraph.config.ConfigUtil -import org.eclipse.lsp4j.jsonrpc.Launcher import java.io.* import java.net.Socket import java.net.URI import java.nio.file.* import java.util.* import java.util.concurrent.* +import org.eclipse.lsp4j.jsonrpc.Launcher /** * Orchestrator for the Cody agent, which is a Node.js program that implements the prompt logic for diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt index 6a572cabcc..58bdbbf4e7 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt @@ -43,13 +43,16 @@ interface CodyAgentServer { @JsonNotification("extensionConfiguration/didChange") fun configurationDidChange(document: ExtensionConfiguration) - @JsonNotification("textDocument/didFocus") fun textDocumentDidFocus(document: ProtocolTextDocument) + @JsonNotification("textDocument/didFocus") + fun textDocumentDidFocus(document: ProtocolTextDocument) @JsonNotification("textDocument/didOpen") fun textDocumentDidOpen(document: ProtocolTextDocument) - @JsonNotification("textDocument/didChange") fun textDocumentDidChange(document: ProtocolTextDocument) + @JsonNotification("textDocument/didChange") + fun textDocumentDidChange(document: ProtocolTextDocument) - @JsonNotification("textDocument/didClose") fun textDocumentDidClose(document: ProtocolTextDocument) + @JsonNotification("textDocument/didClose") + fun textDocumentDidClose(document: ProtocolTextDocument) @JsonNotification("textDocument/didSave") fun textDocumentDidSave(document: ProtocolTextDocument) @@ -64,12 +67,11 @@ interface CodyAgentServer { @JsonRequest("webview/receiveMessage") fun webviewReceiveMessage(params: WebviewReceiveMessageParams): CompletableFuture - @JsonRequest("editTask/accept") - fun editTaskAccept(id: String): CompletableFuture - @JsonRequest("editTask/undo") - fun editTaskUndo(id: String): CompletableFuture - @JsonRequest("editTask/cancel") - fun editTaskCancel(id: String): CompletableFuture + @JsonRequest("editTask/accept") fun editTaskAccept(id: String): CompletableFuture + + @JsonRequest("editTask/undo") fun editTaskUndo(id: String): CompletableFuture + + @JsonRequest("editTask/cancel") fun editTaskCancel(id: String): CompletableFuture @JsonRequest("editTask/getFoldingRanges") fun getFoldingRanges(params: GetFoldingRangeParams): CompletableFuture diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/IconsParams.kt b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/IconsParams.kt index 05c49d9be3..fc44fc3809 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/IconsParams.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/IconsParams.kt @@ -1,6 +1,6 @@ package com.sourcegraph.cody.agent.protocol data class IconsParams( - val value: String? = null, - val position: Int? = null, + val value: String? = null, + val position: Int? = null, ) diff --git a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TitleParams.kt b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TitleParams.kt index d550b0d7d4..bfbb0f3fb4 100644 --- a/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TitleParams.kt +++ b/src/main/kotlin/com/sourcegraph/cody/agent/protocol/TitleParams.kt @@ -1,6 +1,6 @@ package com.sourcegraph.cody.agent.protocol data class TitleParams( - val text: String? = null, - val icons: List? = null, + val text: String? = null, + val icons: List? = null, ) diff --git a/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyEditorFactoryListener.kt b/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyEditorFactoryListener.kt index 4b7fef3d83..57d4f34dc1 100644 --- a/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyEditorFactoryListener.kt +++ b/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyEditorFactoryListener.kt @@ -176,7 +176,8 @@ class CodyEditorFactoryListener : EditorFactoryListener { ) { val file = FileDocumentManager.getInstance().getFile(editor.document) ?: return - val document = ProtocolTextDocument.fromVirtualFile(file, editor.document.text, getSelection(editor)) + val document = + ProtocolTextDocument.fromVirtualFile(file, editor.document.text, getSelection(editor)) val project = editor.project ?: return diff --git a/src/main/kotlin/com/sourcegraph/cody/edit/FixupService.kt b/src/main/kotlin/com/sourcegraph/cody/edit/FixupService.kt index 78a429df50..2cfe2414fe 100644 --- a/src/main/kotlin/com/sourcegraph/cody/edit/FixupService.kt +++ b/src/main/kotlin/com/sourcegraph/cody/edit/FixupService.kt @@ -68,15 +68,17 @@ class FixupService(val project: Project) : Disposable { if (op.edits == null) { logger.warn("Workspace edit operation has no edits") } else { - // If there is a pending session, assume that it is the one that caused the edit. - val session: FixupSession? - if (pendingSessions.isNotEmpty()) { - session = pendingSessions.first() - } else { - // TODO: This is what I'd like to be able to do, but it requires a protocol change: - //session = activeSessions[op.id] - session = activeSessions.values.firstOrNull() - } + // If there is a pending session, assume that it is the one that caused the + // edit. + val session: FixupSession? = + if (pendingSessions.isNotEmpty()) { + pendingSessions.first() + } else { + // TODO: This is what I'd like to be able to do, but it requires a + // protocol change: + // session = activeSessions[op.id] + activeSessions.values.firstOrNull() + } if (session == null) { logger.warn("No sessions found for performing inline edits") } else { diff --git a/src/main/kotlin/com/sourcegraph/cody/edit/FixupSession.kt b/src/main/kotlin/com/sourcegraph/cody/edit/FixupSession.kt index bd67cd9a2a..5c0992c82f 100644 --- a/src/main/kotlin/com/sourcegraph/cody/edit/FixupSession.kt +++ b/src/main/kotlin/com/sourcegraph/cody/edit/FixupSession.kt @@ -59,7 +59,7 @@ abstract class FixupSession(val controller: FixupService, val editor: Editor) : @RequiresEdt private fun triggerDocumentCodeAsync() { - // This caret lookup requires us to be on the EDT. + // This caret lookup requires us to be on the EDT. val caret = editor.caretModel.primaryCaret.offset FixupService.backgroundThread { @@ -168,7 +168,7 @@ abstract class FixupSession(val controller: FixupService, val editor: Editor) : lensGroup = group var range = selectionRange if (range == null) { - // Be defensive, as the protocol has been fragile with respect to selection ranges. + // Be defensive, as the protocol has been fragile with respect to selection ranges. logger.warn("No selection range for session: $this") // Last-ditch effort to show it somewhere other than top of file. val position = Position(editor.caretModel.currentCaret.logicalPosition.line, 0) diff --git a/src/main/kotlin/com/sourcegraph/cody/edit/widget/LensAction.kt b/src/main/kotlin/com/sourcegraph/cody/edit/widget/LensAction.kt index 586c67a5a6..3eb3e75235 100644 --- a/src/main/kotlin/com/sourcegraph/cody/edit/widget/LensAction.kt +++ b/src/main/kotlin/com/sourcegraph/cody/edit/widget/LensAction.kt @@ -2,7 +2,6 @@ package com.sourcegraph.cody.edit.widget import com.intellij.openapi.editor.event.EditorMouseEvent import com.intellij.ui.JBColor -import com.sourcegraph.cody.edit.DocumentCodeSession import com.sourcegraph.cody.edit.FixupSession import java.awt.Font import java.awt.FontMetrics diff --git a/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt b/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt index d0a10c9dbd..ca6499b18a 100644 --- a/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt +++ b/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt @@ -16,9 +16,9 @@ import com.sourcegraph.cody.config.CodyAuthenticationManager import com.sourcegraph.cody.config.ServerAuthLoader import com.sourcegraph.cody.config.SourcegraphServerPath import com.sourcegraph.cody.config.SourcegraphServerPath.Companion.from -import org.jetbrains.annotations.Contract import java.nio.file.Path import java.nio.file.Paths +import org.jetbrains.annotations.Contract object ConfigUtil { const val DOTCOM_URL = "https://sourcegraph.com/"