|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License |
| 3 | + |
| 4 | +import { Event, Disposable, WorkspaceFolder } from 'vscode'; |
| 5 | +import { EnvironmentTools } from '../../apiTypes'; |
| 6 | + |
| 7 | +export type CreateEnvironmentUserActions = 'Back' | 'Cancel'; |
| 8 | +export type EnvironmentProviderId = string; |
| 9 | + |
| 10 | +/** |
| 11 | + * Options used when creating a Python environment. |
| 12 | + */ |
| 13 | +export interface CreateEnvironmentOptions { |
| 14 | + /** |
| 15 | + * Default `true`. If `true`, the environment creation handler is expected to install packages. |
| 16 | + */ |
| 17 | + installPackages?: boolean; |
| 18 | + |
| 19 | + /** |
| 20 | + * Default `true`. If `true`, the environment creation provider is expected to add the environment to ignore list |
| 21 | + * for the source control. |
| 22 | + */ |
| 23 | + ignoreSourceControl?: boolean; |
| 24 | + |
| 25 | + /** |
| 26 | + * Default `false`. If `true` the creation provider should show back button when showing QuickPick or QuickInput. |
| 27 | + */ |
| 28 | + showBackButton?: boolean; |
| 29 | + |
| 30 | + /** |
| 31 | + * Default `true`. If `true`, the environment after creation will be selected. |
| 32 | + */ |
| 33 | + selectEnvironment?: boolean; |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Params passed on `onWillCreateEnvironment` event handler. |
| 38 | + */ |
| 39 | +export interface EnvironmentWillCreateEvent { |
| 40 | + /** |
| 41 | + * Options used to create a Python environment. |
| 42 | + */ |
| 43 | + options: CreateEnvironmentOptions | undefined; |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Params passed on `onDidCreateEnvironment` event handler. |
| 48 | + */ |
| 49 | +export interface EnvironmentDidCreateEvent extends CreateEnvironmentResult { |
| 50 | + /** |
| 51 | + * Options used to create the Python environment. |
| 52 | + */ |
| 53 | + options: CreateEnvironmentOptions | undefined; |
| 54 | +} |
| 55 | + |
| 56 | +export interface CreateEnvironmentResult { |
| 57 | + /** |
| 58 | + * Workspace folder associated with the environment. |
| 59 | + */ |
| 60 | + workspaceFolder: WorkspaceFolder | undefined; |
| 61 | + |
| 62 | + /** |
| 63 | + * Path to the executable python in the environment |
| 64 | + */ |
| 65 | + path: string | undefined; |
| 66 | + |
| 67 | + /** |
| 68 | + * User action that resulted in exit from the create environment flow. |
| 69 | + */ |
| 70 | + action: CreateEnvironmentUserActions | undefined; |
| 71 | + |
| 72 | + /** |
| 73 | + * Error if any occurred during environment creation. |
| 74 | + */ |
| 75 | + error: Error | undefined; |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * Extensions that want to contribute their own environment creation can do that by registering an object |
| 80 | + * that implements this interface. |
| 81 | + */ |
| 82 | +export interface CreateEnvironmentProvider { |
| 83 | + /** |
| 84 | + * This API is called when user selects this provider from a QuickPick to select the type of environment |
| 85 | + * user wants. This API is expected to show a QuickPick or QuickInput to get the user input and return |
| 86 | + * the path to the Python executable in the environment. |
| 87 | + * |
| 88 | + * @param {CreateEnvironmentOptions} [options] Options used to create a Python environment. |
| 89 | + * |
| 90 | + * @returns a promise that resolves to the path to the |
| 91 | + * Python executable in the environment. Or any action taken by the user, such as back or cancel. |
| 92 | + */ |
| 93 | + createEnvironment(options?: CreateEnvironmentOptions): Promise<CreateEnvironmentResult | undefined>; |
| 94 | + |
| 95 | + /** |
| 96 | + * Unique ID for the creation provider, typically <ExtensionId>:<environment-type | guid> |
| 97 | + */ |
| 98 | + id: EnvironmentProviderId; |
| 99 | + |
| 100 | + /** |
| 101 | + * Display name for the creation provider. |
| 102 | + */ |
| 103 | + name: string; |
| 104 | + |
| 105 | + /** |
| 106 | + * Description displayed to the user in the QuickPick to select environment provider. |
| 107 | + */ |
| 108 | + description: string; |
| 109 | + |
| 110 | + /** |
| 111 | + * Tools used to manage this environment. e.g., ['conda']. In the most to least priority order |
| 112 | + * for resolving and working with the environment. |
| 113 | + */ |
| 114 | + tools: EnvironmentTools[]; |
| 115 | +} |
| 116 | + |
| 117 | +export interface ProposedCreateEnvironmentAPI { |
| 118 | + /** |
| 119 | + * This API can be used to detect when the environment creation starts for any registered |
| 120 | + * provider (including internal providers). This will also receive any options passed in |
| 121 | + * or defaults used to create environment. |
| 122 | + */ |
| 123 | + onWillCreateEnvironment: Event<EnvironmentWillCreateEvent>; |
| 124 | + |
| 125 | + /** |
| 126 | + * This API can be used to detect when the environment provider exits for any registered |
| 127 | + * provider (including internal providers). This will also receive created environment path, |
| 128 | + * any errors, or user actions taken from the provider. |
| 129 | + */ |
| 130 | + onDidCreateEnvironment: Event<EnvironmentDidCreateEvent>; |
| 131 | + |
| 132 | + /** |
| 133 | + * This API will show a QuickPick to select an environment provider from available list of |
| 134 | + * providers. Based on the selection the `createEnvironment` will be called on the provider. |
| 135 | + */ |
| 136 | + createEnvironment(options?: CreateEnvironmentOptions): Promise<CreateEnvironmentResult | undefined>; |
| 137 | + |
| 138 | + /** |
| 139 | + * This API should be called to register an environment creation provider. It returns |
| 140 | + * a (@link Disposable} which can be used to remove the registration. |
| 141 | + */ |
| 142 | + registerCreateEnvironmentProvider(provider: CreateEnvironmentProvider): Disposable; |
| 143 | +} |
0 commit comments