Skip to content

Commit

Permalink
Initiial
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Aug 7, 2024
1 parent 71f48f4 commit cbd7032
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
29 changes: 29 additions & 0 deletions src/main/java/com/sourcegraph/cody/agent/CodyAgentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileChooser.FileChooserFactory;
import com.intellij.openapi.fileChooser.FileSaverDescriptor;
import com.intellij.openapi.fileChooser.FileSaverDialog;
import com.intellij.openapi.vfs.VirtualFileWrapper;
import com.sourcegraph.cody.agent.protocol.*;
import com.sourcegraph.cody.agent.protocol_generated.DisplayCodeLensParams;
import com.sourcegraph.cody.agent.protocol_generated.EditTask;
import com.sourcegraph.cody.agent.protocol_generated.SaveDialogOptionsParams;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -202,4 +213,22 @@ public void webviewPostMessage(@NotNull WebviewPostMessageParams params) {

logger.debug(String.format("webview/postMessage %s: %s", params.getId(), params.getMessage()));
}

@JsonRequest("window/showSaveDialog")
public CompletableFuture<String> window_showSaveDialog(SaveDialogOptionsParams params) {
Path defaultPath = Paths.get(Objects.requireNonNull(params.getDefaultUri()));
Map<String, List<String>> filters = params.getFilters();
List<String> allValues =
Objects.requireNonNull(filters).values().stream()
.flatMap(List::stream)
.collect(Collectors.toList());

FileSaverDescriptor descriptor =
new FileSaverDescriptor("Save", "Save file", allValues.toArray(new String[0]));
FileSaverDialog saveFileDialog =
FileChooserFactory.getInstance().createSaveFileDialog(descriptor, project);
VirtualFileWrapper savedFile =
saveFileDialog.save(defaultPath, defaultPath.getFileName().toString());
return CompletableFuture.completedFuture(savedFile.getFile().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class CodyAgentClientTest : BasePlatformTestCase() {
const val WEBVIEW_ID: String = "unused-webview-id"
}

@Volatile
var lastMessage: ConfigFeatures? = null
@Volatile var lastMessage: ConfigFeatures? = null

// Use lock/condition to synchronize between observer being invoked
// and the test being able to assert.
Expand Down Expand Up @@ -43,11 +42,11 @@ class CodyAgentClientTest : BasePlatformTestCase() {
WebviewPostMessageParams(
id = WEBVIEW_ID,
message =
ExtensionMessage(
type = ExtensionMessage.Type.SET_CONFIG_FEATURES,
errors = null,
configFeatures = expected,
)))
ExtensionMessage(
type = ExtensionMessage.Type.SET_CONFIG_FEATURES,
errors = null,
configFeatures = expected,
)))
PlatformTestUtil.dispatchAllEventsInIdeEventQueue()
lock.lock()
try {
Expand Down

0 comments on commit cbd7032

Please sign in to comment.