Skip to content

Commit 994f515

Browse files
authored
1 parent f662c0b commit 994f515

File tree

14 files changed

+466
-78
lines changed

14 files changed

+466
-78
lines changed

examples/sample1/src/api.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ export type DidChangeEnvironmentsEventArgs = {
316316
*/
317317
export type ResolveEnvironmentContext = Uri;
318318

319+
export interface QuickCreateConfig {
320+
/**
321+
* The description of the quick create step.
322+
*/
323+
readonly description: string;
324+
325+
/**
326+
* The detail of the quick create step.
327+
*/
328+
readonly detail?: string;
329+
}
330+
319331
/**
320332
* Interface representing an environment manager.
321333
*/
@@ -360,12 +372,19 @@ export interface EnvironmentManager {
360372
*/
361373
readonly log?: LogOutputChannel;
362374

375+
/**
376+
* The quick create details for the environment manager. Having this method also enables the quick create feature
377+
* for the environment manager.
378+
*/
379+
quickCreateConfig?(): QuickCreateConfig | undefined;
380+
363381
/**
364382
* Creates a new Python environment within the specified scope.
365383
* @param scope - The scope within which to create the environment.
384+
* @param options - Optional parameters for creating the Python environment.
366385
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
367386
*/
368-
create?(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
387+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
369388

370389
/**
371390
* Removes the specified Python environment.
@@ -705,6 +724,9 @@ export interface DidChangePythonProjectsEventArgs {
705724
removed: PythonProject[];
706725
}
707726

727+
/**
728+
* Options for package management.
729+
*/
708730
export type PackageManagementOptions =
709731
| {
710732
/**
@@ -747,6 +769,28 @@ export type PackageManagementOptions =
747769
uninstall: string[];
748770
};
749771

772+
/**
773+
* Options for creating a Python environment.
774+
*/
775+
export interface CreateEnvironmentOptions {
776+
/**
777+
* Provides some context about quick create based on user input.
778+
* - if true, the environment should be created without any user input or prompts.
779+
* - if false, the environment creation can show user input or prompts.
780+
* This also means user explicitly skipped the quick create option.
781+
* - if undefined, the environment creation can show user input or prompts.
782+
* You can show quick create option to the user if you support it.
783+
*/
784+
quickCreate?: boolean;
785+
/**
786+
* Packages to install in addition to the automatically picked packages as a part of creating environment.
787+
*/
788+
additionalPackages?: string[];
789+
}
790+
791+
/**
792+
* Object representing the process started using run in background API.
793+
*/
750794
export interface PythonProcess {
751795
/**
752796
* The process ID of the Python process.
@@ -807,9 +851,13 @@ export interface PythonEnvironmentManagementApi {
807851
* Create a Python environment using environment manager associated with the scope.
808852
*
809853
* @param scope Where the environment is to be created.
854+
* @param options Optional parameters for creating the Python environment.
810855
* @returns The Python environment created. `undefined` if not created.
811856
*/
812-
createEnvironment(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
857+
createEnvironment(
858+
scope: CreateEnvironmentScope,
859+
options?: CreateEnvironmentOptions,
860+
): Promise<PythonEnvironment | undefined>;
813861

814862
/**
815863
* Remove a Python environment.

examples/sample1/src/sampleEnvManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MarkdownString, LogOutputChannel, Event } from 'vscode';
22
import {
3+
CreateEnvironmentOptions,
34
CreateEnvironmentScope,
45
DidChangeEnvironmentEventArgs,
56
DidChangeEnvironmentsEventArgs,
@@ -8,6 +9,7 @@ import {
89
GetEnvironmentsScope,
910
IconPath,
1011
PythonEnvironment,
12+
QuickCreateConfig,
1113
RefreshEnvironmentsScope,
1214
ResolveEnvironmentContext,
1315
SetEnvironmentScope,
@@ -31,7 +33,13 @@ export class SampleEnvManager implements EnvironmentManager {
3133
this.log = log;
3234
}
3335

34-
create?(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined> {
36+
quickCreateConfig(): QuickCreateConfig | undefined {
37+
// Code to provide quick create configuration goes here
38+
39+
throw new Error('Method not implemented.');
40+
}
41+
42+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined> {
3543
// Code to handle creating environments goes here
3644

3745
throw new Error('Method not implemented.');

src/api.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ export type DidChangeEnvironmentsEventArgs = {
316316
*/
317317
export type ResolveEnvironmentContext = Uri;
318318

319+
export interface QuickCreateConfig {
320+
/**
321+
* The description of the quick create step.
322+
*/
323+
readonly description: string;
324+
325+
/**
326+
* The detail of the quick create step.
327+
*/
328+
readonly detail?: string;
329+
}
330+
319331
/**
320332
* Interface representing an environment manager.
321333
*/
@@ -360,12 +372,19 @@ export interface EnvironmentManager {
360372
*/
361373
readonly log?: LogOutputChannel;
362374

375+
/**
376+
* The quick create details for the environment manager. Having this method also enables the quick create feature
377+
* for the environment manager.
378+
*/
379+
quickCreateConfig?(): QuickCreateConfig | undefined;
380+
363381
/**
364382
* Creates a new Python environment within the specified scope.
365383
* @param scope - The scope within which to create the environment.
384+
* @param options - Optional parameters for creating the Python environment.
366385
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
367386
*/
368-
create?(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
387+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
369388

370389
/**
371390
* Removes the specified Python environment.
@@ -747,6 +766,28 @@ export type PackageManagementOptions =
747766
uninstall: string[];
748767
};
749768

769+
/**
770+
* Options for creating a Python environment.
771+
*/
772+
export interface CreateEnvironmentOptions {
773+
/**
774+
* Provides some context about quick create based on user input.
775+
* - if true, the environment should be created without any user input or prompts.
776+
* - if false, the environment creation can show user input or prompts.
777+
* This also means user explicitly skipped the quick create option.
778+
* - if undefined, the environment creation can show user input or prompts.
779+
* You can show quick create option to the user if you support it.
780+
*/
781+
quickCreate?: boolean;
782+
/**
783+
* Packages to install in addition to the automatically picked packages as a part of creating environment.
784+
*/
785+
additionalPackages?: string[];
786+
}
787+
788+
/**
789+
* Object representing the process started using run in background API.
790+
*/
750791
export interface PythonProcess {
751792
/**
752793
* The process ID of the Python process.
@@ -807,9 +848,13 @@ export interface PythonEnvironmentManagementApi {
807848
* Create a Python environment using environment manager associated with the scope.
808849
*
809850
* @param scope Where the environment is to be created.
851+
* @param options Optional parameters for creating the Python environment.
810852
* @returns The Python environment created. `undefined` if not created.
811853
*/
812-
createEnvironment(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
854+
createEnvironment(
855+
scope: CreateEnvironmentScope,
856+
options?: CreateEnvironmentOptions,
857+
): Promise<PythonEnvironment | undefined>;
813858

814859
/**
815860
* Remove a Python environment.

src/common/localize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export namespace Common {
1111
export const viewLogs = l10n.t('View Logs');
1212
export const yes = l10n.t('Yes');
1313
export const no = l10n.t('No');
14+
export const quickCreate = l10n.t('Quick Create');
1415
}
1516

1617
export namespace Interpreter {
@@ -134,6 +135,9 @@ export namespace CondaStrings {
134135
export const condaCreateFailed = l10n.t('Failed to create conda environment');
135136
export const condaRemoveFailed = l10n.t('Failed to remove conda environment');
136137
export const condaExists = l10n.t('Environment already exists');
138+
139+
export const quickCreateCondaNoEnvRoot = l10n.t('No conda environment root found');
140+
export const quickCreateCondaNoName = l10n.t('Could not generate a name for env');
137141
}
138142

139143
export namespace ProjectCreatorString {

src/common/pickers/environments.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ async function createEnvironment(
8080
const manager = managers.find((m) => m.id === managerId);
8181
if (manager) {
8282
try {
83-
const env = await manager.create(options.projects.map((p) => p.uri));
83+
const env = await manager.create(
84+
options.projects.map((p) => p.uri),
85+
undefined,
86+
);
8487
return env;
8588
} catch (ex) {
8689
if (ex === QuickInputButtons.Back) {

src/common/pickers/managers.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import { InternalEnvironmentManager, InternalPackageManager } from '../../intern
44
import { Common, Pickers } from '../localize';
55
import { showQuickPickWithButtons, showQuickPick } from '../window.apis';
66

7+
function getDescription(mgr: InternalEnvironmentManager | InternalPackageManager): string | undefined {
8+
if (mgr.description) {
9+
return mgr.description;
10+
}
11+
if (mgr.tooltip) {
12+
const tooltip = mgr.tooltip;
13+
if (typeof tooltip === 'string') {
14+
return tooltip;
15+
}
16+
return tooltip.value;
17+
}
18+
return undefined;
19+
}
20+
721
export async function pickEnvironmentManager(
822
managers: InternalEnvironmentManager[],
923
defaultManagers?: InternalEnvironmentManager[],
@@ -18,14 +32,25 @@ export async function pickEnvironmentManager(
1832

1933
const items: (QuickPickItem | (QuickPickItem & { id: string }))[] = [];
2034
if (defaultManagers && defaultManagers.length > 0) {
35+
items.push({
36+
label: Common.recommended,
37+
kind: QuickPickItemKind.Separator,
38+
});
39+
if (defaultManagers.length === 1 && defaultManagers[0].supportsQuickCreate) {
40+
const details = defaultManagers[0].quickCreateConfig();
41+
if (details) {
42+
items.push({
43+
label: Common.quickCreate,
44+
description: details.description,
45+
detail: details.detail,
46+
id: `QuickCreate#${defaultManagers[0].id}`,
47+
});
48+
}
49+
}
2150
items.push(
22-
{
23-
label: Common.recommended,
24-
kind: QuickPickItemKind.Separator,
25-
},
2651
...defaultManagers.map((defaultMgr) => ({
2752
label: defaultMgr.displayName,
28-
description: defaultMgr.description,
53+
description: getDescription(defaultMgr),
2954
id: defaultMgr.id,
3055
})),
3156
{
@@ -39,7 +64,7 @@ export async function pickEnvironmentManager(
3964
.filter((m) => !defaultManagers?.includes(m))
4065
.map((m) => ({
4166
label: m.displayName,
42-
description: m.description,
67+
description: getDescription(m),
4368
id: m.id,
4469
})),
4570
);
@@ -71,7 +96,7 @@ export async function pickPackageManager(
7196
},
7297
...defaultManagers.map((defaultMgr) => ({
7398
label: defaultMgr.displayName,
74-
description: defaultMgr.description,
99+
description: getDescription(defaultMgr),
75100
id: defaultMgr.id,
76101
})),
77102
{
@@ -85,7 +110,7 @@ export async function pickPackageManager(
85110
.filter((m) => !defaultManagers?.includes(m))
86111
.map((m) => ({
87112
label: m.displayName,
88-
description: m.description,
113+
description: getDescription(m),
89114
id: m.id,
90115
})),
91116
);

0 commit comments

Comments
 (0)