forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathcreateEnvQuickPick.ts
More file actions
54 lines (49 loc) · 1.78 KB
/
createEnvQuickPick.ts
File metadata and controls
54 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License
import { QuickPickItem } from 'vscode';
import { CreateEnv } from '../../common/utils/localize';
import { showQuickPick } from '../../common/vscodeApis/windowApis';
import { traceError } from '../../logging';
import { createEnvironment } from './createEnvironment';
import { CreateEnvironmentOptions, CreateEnvironmentProvider } from './types';
interface CreateEnvironmentProviderQuickPickItem extends QuickPickItem {
id: string;
}
async function showCreateEnvironmentQuickPick(
providers: readonly CreateEnvironmentProvider[],
): Promise<CreateEnvironmentProvider | undefined> {
const items: CreateEnvironmentProviderQuickPickItem[] = providers.map((p) => ({
label: p.name,
description: p.description,
id: p.id,
}));
const selected = await showQuickPick(items, {
title: CreateEnv.providersQuickPickTitle,
matchOnDescription: true,
ignoreFocusOut: true,
});
if (selected) {
const selections = providers.filter((p) => p.id === selected.id);
if (selections.length > 0) {
return selections[0];
}
}
return undefined;
}
export async function handleCreateEnvironmentCommand(
providers: readonly CreateEnvironmentProvider[],
options?: CreateEnvironmentOptions,
): Promise<string | undefined> {
if (providers.length === 1) {
return createEnvironment(providers[0], options);
}
if (providers.length > 1) {
const provider = await showCreateEnvironmentQuickPick(providers);
if (provider) {
return createEnvironment(provider, options);
}
} else {
traceError('No Environment Creation providers were registered.');
}
return undefined;
}