item);
+ }
+ }),
+ input.onDidChangeSelection((items) => resolve(items[0]))
+ // input.onDidHide(() => {
+ // (async () => {
+ // reject(
+ // shouldResume && (await shouldResume())
+ // ? InputFlowAction.resume
+ // : InputFlowAction.cancel
+ // );
+ // })().catch(reject);
+ // })
+ );
+ if (this.current) {
+ this.current.dispose();
+ }
+ this.current = input;
+ this.current.show();
+ });
+ } finally {
+ disposables.forEach((d) => d.dispose());
+ }
+ }
+
+ async showInputBox({
+ title,
+ step,
+ totalSteps,
+ value,
+ prompt,
+ validate,
+ buttons,
+ ignoreFocusOut,
+ placeholder,
+ // shouldResume,
+ }: P) {
+ const disposables: Disposable[] = [];
+ try {
+ return await new Promise<
+ string | (P extends { buttons: (infer I)[] } ? I : never)
+ >((resolve, reject) => {
+ const input = window.createInputBox();
+ input.title = title;
+ input.step = step;
+ input.totalSteps = totalSteps;
+ input.value = value || "";
+ input.prompt = prompt;
+ input.ignoreFocusOut = ignoreFocusOut ?? false;
+ input.placeholder = placeholder;
+ input.buttons = [
+ ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []),
+ ...(buttons || []),
+ ];
+ let validating = validate("");
+ disposables.push(
+ input.onDidTriggerButton((item) => {
+ if (item === QuickInputButtons.Back) {
+ reject(InputFlowAction.back);
+ } else {
+ resolve(item);
+ }
+ }),
+ input.onDidAccept(async () => {
+ const value = input.value;
+ input.enabled = false;
+ input.busy = true;
+ if (!(await validate(value))) {
+ resolve(value);
+ }
+ input.enabled = true;
+ input.busy = false;
+ }),
+ input.onDidChangeValue(async (text) => {
+ const current = validate(text);
+ validating = current;
+ const validationMessage = await current;
+ if (current === validating) {
+ input.validationMessage = validationMessage;
+ }
+ })
+ // input.onDidHide(() => {
+ // (async () => {
+ // reject(
+ // shouldResume && (await shouldResume())
+ // ? InputFlowAction.resume
+ // : InputFlowAction.cancel
+ // );
+ // })().catch(reject);
+ // })
+ );
+ if (this.current) {
+ this.current.dispose();
+ }
+ this.current = input;
+ this.current.show();
+ });
+ } finally {
+ disposables.forEach((d) => d.dispose());
+ }
+ }
+}
diff --git a/packages/cloudflare-workers-bindings-extension/src/bindings.ts b/packages/cloudflare-workers-bindings-extension/src/bindings.ts
index 817b39fdebbd..5e4c7f715daf 100644
--- a/packages/cloudflare-workers-bindings-extension/src/bindings.ts
+++ b/packages/cloudflare-workers-bindings-extension/src/bindings.ts
@@ -200,26 +200,29 @@ export class BindingsProvider implements vscode.TreeDataProvider {
// Finds the first wrangler config file in the workspace and parse it
export async function getWranglerConfig(): Promise {
- const [configUri] = await vscode.workspace.findFiles(
- "wrangler.{toml,jsonc,json}",
- null,
- 1
- );
-
+ const configUri = await getConfigUri();
if (!configUri) {
return null;
}
-
const workspaceFolder = vscode.workspace.getWorkspaceFolder(configUri);
if (!workspaceFolder) {
return null;
}
- const wrangler = await importWrangler(workspaceFolder.uri.fsPath);
+ const wrangler = importWrangler(workspaceFolder.uri.fsPath);
const { rawConfig } = wrangler.experimental_readRawConfig({
config: configUri.fsPath,
});
return rawConfig;
}
+
+export async function getConfigUri(): Promise {
+ const [configUri] = await vscode.workspace.findFiles(
+ "wrangler.{toml,jsonc,json}",
+ null,
+ 1
+ );
+ return configUri;
+}
diff --git a/packages/cloudflare-workers-bindings-extension/src/extension.ts b/packages/cloudflare-workers-bindings-extension/src/extension.ts
index 9da94758ee44..d91a7e71ac4b 100644
--- a/packages/cloudflare-workers-bindings-extension/src/extension.ts
+++ b/packages/cloudflare-workers-bindings-extension/src/extension.ts
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
+import { multiStepInput } from "./add-binding";
import { BindingsProvider } from "./bindings";
export type Result = {
@@ -31,7 +32,12 @@ export async function activate(
"cloudflare-workers-bindings.refresh",
() => bindingsProvider.refresh()
);
-
+ vscode.commands.registerCommand(
+ "cloudflare-workers-bindings.addEntry",
+ async () => {
+ await multiStepInput(context);
+ }
+ );
// Cleanup when the extension is deactivated
context.subscriptions.push(bindingsView, watcher, refreshCommand);
diff --git a/packages/cloudflare-workers-bindings-extension/src/wrangler.ts b/packages/cloudflare-workers-bindings-extension/src/wrangler.ts
index 2e35d08288e2..3f23a1f4e6a9 100644
--- a/packages/cloudflare-workers-bindings-extension/src/wrangler.ts
+++ b/packages/cloudflare-workers-bindings-extension/src/wrangler.ts
@@ -1,4 +1,5 @@
import * as path from "path";
+import * as vscode from "vscode";
export function importWrangler(
workspaceRoot: string