forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathapi.ts
More file actions
66 lines (53 loc) · 1.8 KB
/
api.ts
File metadata and controls
66 lines (53 loc) · 1.8 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
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Event } from 'vscode';
import {
GetRefreshEnvironmentsOptions,
IDiscoveryAPI,
ProgressNotificationEvent,
ProgressReportStage,
PythonLocatorQuery,
TriggerRefreshOptions,
} from './base/locator';
export type GetLocatorFunc = () => Promise<IDiscoveryAPI>;
/**
* The public API for the Python environments component.
*
* Note that this is composed of sub-components.
*/
class PythonEnvironments implements IDiscoveryAPI {
private locator!: IDiscoveryAPI;
constructor(
// These are factories for the sub-components the full component is composed of:
private readonly getLocator: GetLocatorFunc,
) {}
public async activate(): Promise<void> {
this.locator = await this.getLocator();
}
public get onProgress(): Event<ProgressNotificationEvent> {
return this.locator.onProgress;
}
public get refreshState(): ProgressReportStage {
return this.locator.refreshState;
}
public getRefreshPromise(options?: GetRefreshEnvironmentsOptions) {
return this.locator.getRefreshPromise(options);
}
public get onChanged() {
return this.locator.onChanged;
}
public getEnvs(query?: PythonLocatorQuery) {
return this.locator.getEnvs(query);
}
public async resolveEnv(env: string) {
return this.locator.resolveEnv(env);
}
public async triggerRefresh(query?: PythonLocatorQuery, options?: TriggerRefreshOptions) {
return this.locator.triggerRefresh(query, options);
}
}
export async function createPythonEnvironments(getLocator: GetLocatorFunc): Promise<IDiscoveryAPI> {
const api = new PythonEnvironments(getLocator);
await api.activate();
return api;
}