Skip to content

Commit

Permalink
dev: Add implementation for showWorkspaceFolderPick (#1735)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 committed May 31, 2024
1 parent 494a281 commit c230a16
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dev/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { Environment } from "@azure/ms-rest-azure-env";
import * as cp from "child_process";
import { Disposable, Event, InputBoxOptions, LogLevel, LogOutputChannel, MessageItem, MessageOptions, OpenDialogOptions, QuickPickItem, QuickPickOptions, Uri } from "vscode";
import { Disposable, Event, InputBoxOptions, LogLevel, LogOutputChannel, MessageItem, MessageOptions, OpenDialogOptions, QuickPickItem, QuickPickOptions, Uri, WorkspaceFolderPickOptions } from "vscode";
import * as webpack from 'webpack';

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ export declare enum TestInput {
}

export type PromptResult = {
value: string | QuickPickItem | QuickPickItem[] | MessageItem | Uri[];
value: string | QuickPickItem | QuickPickItem[] | MessageItem | Uri[] | WorkspaceFolder;

/**
* True if the user did not change from the default value, currently only supported for `showInputBox`
Expand Down Expand Up @@ -234,6 +234,7 @@ export declare class TestUserInput {
public showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Promise<T>;
public showWarningMessage<T extends MessageItem>(message: string, options: MessageOptions, ...items: T[]): Promise<MessageItem>;
public showOpenDialog(options: OpenDialogOptions): Promise<Uri[]>;
public showWorkspaceFolderPick(options: WorkspaceFolderPickOptions): Promise<WorkspaceFolder>;
}

export interface TestActionContext {
Expand Down
29 changes: 29 additions & 0 deletions dev/src/TestUserInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,35 @@ export class TestUserInput implements types.TestUserInput {
this._onDidFinishPromptEmitter.fire({ value: result });
return result;
}

public async showWorkspaceFolderPick(options: vscodeTypes.WorkspaceFolderPickOptions): Promise<vscodeTypes.WorkspaceFolder> {
let result: vscodeTypes.WorkspaceFolder;
const input: string | RegExp | TestInput | undefined = this._inputs.shift();

if (input === undefined) {
throw new Error(`No more inputs left for call to showWorkspaceFolderPick. Placeholder: ${options.placeHolder}`);
} else if (typeof input === 'string' || input instanceof RegExp) {
const workspaceFolders: readonly vscodeTypes.WorkspaceFolder[] | undefined = this._vscode.workspace.workspaceFolders;
const workspaceFolder: vscodeTypes.WorkspaceFolder | undefined = workspaceFolders?.find(workspace => {
const valuesToTest: string[] = [workspace.name, workspace.uri.path];
if (typeof input === 'string') {
return !!valuesToTest.find(v => v === input);
} else {
return !!valuesToTest.find(v => v.match(input));
}
});

if (!workspaceFolder) {
throw new Error(`Did not find workspace folder with name matching '${input}'.`);
}
result = workspaceFolder;
} else {
throw new Error(`Unexpected input '${input}' for showWorkspaceFolderPick.`);
}

this._onDidFinishPromptEmitter.fire({ value: result });
return result;
}
}


Expand Down

0 comments on commit c230a16

Please sign in to comment.