Skip to content

Commit

Permalink
fixed spotless errors
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyegge committed Mar 16, 2024
1 parent 6034b9e commit 679bea2
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 45 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/sourcegraph/cody/CodyFileEditorListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ 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 =
ApplicationManager.getApplication()
.runReadAction(
(Computable<Document>) () -> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void focusGained(@NotNull Editor editor) {
agent.getServer().textDocumentDidFocus(ProtocolTextDocument.fromVirtualFile(file));
});


CodyAgentCodebase.getInstance(project).onFileOpened(project, file);
}
}
24 changes: 12 additions & 12 deletions src/main/java/com/sourcegraph/cody/agent/CodyAgentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextDocumentEditParams> callback) {
onTextDocumentEdit = callback;
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -64,12 +67,11 @@ interface CodyAgentServer {
@JsonRequest("webview/receiveMessage")
fun webviewReceiveMessage(params: WebviewReceiveMessageParams): CompletableFuture<Any?>

@JsonRequest("editTask/accept")
fun editTaskAccept(id: String): CompletableFuture<Any?>
@JsonRequest("editTask/undo")
fun editTaskUndo(id: String): CompletableFuture<Any?>
@JsonRequest("editTask/cancel")
fun editTaskCancel(id: String): CompletableFuture<Any?>
@JsonRequest("editTask/accept") fun editTaskAccept(id: String): CompletableFuture<Any?>

@JsonRequest("editTask/undo") fun editTaskUndo(id: String): CompletableFuture<Any?>

@JsonRequest("editTask/cancel") fun editTaskCancel(id: String): CompletableFuture<Any?>

@JsonRequest("editTask/getFoldingRanges")
fun getFoldingRanges(params: GetFoldingRangeParams): CompletableFuture<GetFoldingRangeResult>
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sourcegraph.cody.agent.protocol

data class TitleParams(
val text: String? = null,
val icons: List<IconsParams>? = null,
val text: String? = null,
val icons: List<IconsParams>? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 11 additions & 9 deletions src/main/kotlin/com/sourcegraph/cody/edit/FixupService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/sourcegraph/cody/edit/FixupSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down

0 comments on commit 679bea2

Please sign in to comment.