showOpenDialogue host bridge migration (#4651)
* showOpenDialogue host bridge migration * addressing comments --------- Co-authored-by: Cline Evaluation <cline@example.com>
This commit is contained in:
1 parent
3248c37358
commit
4a2dad4552
4 files changed
+55
-12
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as vscode from "vscode"
|
||||
import { ShowOpenDialogueRequest, SelectedResources } from "@/shared/proto/host/window"
|
||||
|
||||
export async function showOpenDialogue(request: ShowOpenDialogueRequest): Promise<SelectedResources> {
|
||||
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) : [],
|
||||
})
|
||||
}
|
||||
@@ -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: [] }
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user