diff --git a/proto/host/window.proto b/proto/host/window.proto index 820a78c5..19a39686 100644 --- a/proto/host/window.proto +++ b/proto/host/window.proto @@ -10,6 +10,7 @@ import "common.proto"; service WindowService { // Opens a text document in the editor and returns editor information. rpc showTextDocument(ShowTextDocumentRequest) returns (TextEditorInfo); + rpc showOpenDialogue(ShowOpenDialogueRequest) returns (SelectedResources); } message ShowTextDocumentRequest { @@ -30,3 +31,18 @@ message TextEditorInfo { optional int32 view_column = 2; bool is_active = 3; } + +message ShowOpenDialogueRequest { + cline.Metadata metadata = 1; + optional bool can_select_many = 2; + optional string open_label = 3; + optional ShowOpenDialogueFilterOption filters = 4; +} + +message ShowOpenDialogueFilterOption { + repeated string files = 1; +} + +message SelectedResources { + repeated string paths = 1; +} diff --git a/src/hosts/vscode/window/showOpenDialogue.ts b/src/hosts/vscode/window/showOpenDialogue.ts new file mode 100644 index 00000000..27163a47 --- /dev/null +++ b/src/hosts/vscode/window/showOpenDialogue.ts @@ -0,0 +1,27 @@ +import * as vscode from "vscode" +import { ShowOpenDialogueRequest, SelectedResources } from "@/shared/proto/host/window" + +export async function showOpenDialogue(request: ShowOpenDialogueRequest): Promise { + const options: vscode.OpenDialogOptions = {} + + if (request.canSelectMany !== undefined) { + options.canSelectMany = request.canSelectMany + } + + if (request.openLabel !== undefined) { + options.openLabel = request.openLabel + } + + if (request.filters?.files) { + options.filters = { + Files: request.filters.files, + } + } + + const selectedResources = await vscode.window.showOpenDialog(options) + + // Convert back to path format + return SelectedResources.create({ + paths: selectedResources ? selectedResources.map((uri) => uri.fsPath) : [], + }) +} diff --git a/src/integrations/misc/process-files.ts b/src/integrations/misc/process-files.ts index 5f9b2269..829bc8ce 100644 --- a/src/integrations/misc/process-files.ts +++ b/src/integrations/misc/process-files.ts @@ -2,6 +2,8 @@ import * as vscode from "vscode" import fs from "fs/promises" import * as path from "path" import sizeOf from "image-size" +import { getHostBridgeProvider } from "@/hosts/host-providers" +import { ShowOpenDialogueRequest } from "@/shared/proto/host/window" /** * Supports processing of images and other file types @@ -11,15 +13,17 @@ export async function selectFiles(imagesAllowed: boolean): Promise<{ images: str const IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "webp"] // supported by anthropic and openrouter const OTHER_FILE_EXTENSIONS = ["xml", "json", "txt", "log", "md", "docx", "ipynb", "pdf", "xlsx", "csv"] - const options: vscode.OpenDialogOptions = { - canSelectMany: true, - openLabel: "Select", - filters: { - Files: imagesAllowed ? [...IMAGE_EXTENSIONS, ...OTHER_FILE_EXTENSIONS] : OTHER_FILE_EXTENSIONS, - }, - } + const showDialogueResponse = await getHostBridgeProvider().windowClient.showOpenDialogue( + ShowOpenDialogueRequest.create({ + canSelectMany: true, + openLabel: "Select", + filters: { + files: imagesAllowed ? [...IMAGE_EXTENSIONS, ...OTHER_FILE_EXTENSIONS] : OTHER_FILE_EXTENSIONS, + }, + }), + ) - const fileUris = await vscode.window.showOpenDialog(options) + const fileUris = showDialogueResponse.paths.map((path) => vscode.Uri.file(path)) if (!fileUris || fileUris.length === 0) { return { images: [], files: [] } diff --git a/standalone/runtime-files/vscode/vscode-stubs.js b/standalone/runtime-files/vscode/vscode-stubs.js index 4d4bcc57..b2123d1f 100644 --- a/standalone/runtime-files/vscode/vscode-stubs.js +++ b/standalone/runtime-files/vscode/vscode-stubs.js @@ -672,10 +672,6 @@ vscode.window.showWorkspaceFolderPick = function (options) { console.log("Called stubbed function: vscode.window.showWorkspaceFolderPick") return Promise.resolve(null) } -vscode.window.showOpenDialog = function (options) { - console.log("Called stubbed function: vscode.window.showOpenDialog") - return [] -} vscode.window.showSaveDialog = function (options) { console.log("Called stubbed function: vscode.window.showSaveDialog") return Promise.resolve(null)