1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- /* eslint-disable @typescript-eslint/ban-types */
5
- /* eslint-disable @typescript-eslint/no-explicit-any */
6
- // Copyright (c) Microsoft Corporation. All rights reserved.
7
- // Licensed under the MIT License.
8
-
9
- import { Event , Uri } from 'vscode' ;
4
+ import { Event , Uri , WorkspaceFolder } from 'vscode' ;
10
5
11
6
// https://github.com/microsoft/vscode-python/wiki/Proposed-Environment-APIs
12
7
@@ -15,7 +10,7 @@ export interface IProposedExtensionAPI {
15
10
/**
16
11
* This event is triggered when the active environment changes.
17
12
*/
18
- onDidActiveEnvironmentChanged : Event < ActiveEnvironmentChangedParams > ;
13
+ onDidChangeActiveEnvironment : Event < ActiveEnvironmentChangedParams > ;
19
14
/**
20
15
* Returns the path to the python binary selected by the user or as in the settings.
21
16
* This is just the path to the python binary, this does not provide activation or any
@@ -24,44 +19,41 @@ export interface IProposedExtensionAPI {
24
19
* returns what ever is set for the workspace.
25
20
* @param resource : Uri of a file or workspace
26
21
*/
27
- getActiveEnvironmentPath ( resource ?: Resource ) : Promise < EnvPathType | undefined > ;
22
+ getActiveEnvironmentPath ( resource ?: Resource ) : Promise < EnvironmentPath | undefined > ;
28
23
/**
29
- * Returns details for the given interpreter . Details such as absolute interpreter path,
24
+ * Returns details for the given python executable . Details such as absolute python executable path,
30
25
* version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under
31
26
* metadata field.
32
- * @param path : Full path to environment folder or interpreter whose details you need.
27
+ * @param path : Full path to environment folder or python executable whose details you need.
33
28
* @param options : [optional]
34
29
* * useCache : When true, cache is checked first for any data, returns even if there
35
30
* is partial data.
36
31
*/
37
32
getEnvironmentDetails (
38
- path : string ,
33
+ path : EnvironmentPath | UniquePathType ,
39
34
options ?: EnvironmentDetailsOptions ,
40
35
) : Promise < EnvironmentDetails | undefined > ;
41
36
/**
42
37
* Sets the active environment path for the python extension for the resource. Configuration target
43
38
* will always be the workspace folder.
44
- * @param path : Full path to environment folder or interpreter to set.
39
+ * @param path : Full path to environment folder or python executable to set.
45
40
* @param resource : [optional] Uri of a file ro workspace to scope to a particular workspace
46
41
* folder.
47
42
*/
48
- setActiveEnvironment ( path : string , resource ?: Resource ) : Promise < void > ;
43
+ setActiveEnvironment ( path : EnvironmentPath | UniquePathType , resource ?: Resource ) : Promise < void > ;
49
44
locator : {
50
45
/**
51
46
* Returns paths to environments that uniquely identifies an environment found by the extension
52
47
* at the time of calling. This API will *not* trigger a refresh. If a refresh is going on it
53
48
* will *not* wait for the refresh to finish. This will return what is known so far. To get
54
49
* complete list `await` on promise returned by `getRefreshPromise()`.
55
- *
56
- * Environments lacking an interpreter are identified by environment folder paths,
57
- * whereas other envs can be identified using executable path.
58
50
*/
59
- getEnvironmentPaths ( ) : Promise < EnvPathType [ ] | undefined > ;
51
+ getEnvironmentPaths ( ) : Promise < EnvironmentPath [ ] | undefined > ;
60
52
/**
61
53
* This event is triggered when the known environment list changes, like when a environment
62
54
* is found, existing environment is removed, or some details changed on an environment.
63
55
*/
64
- onDidEnvironmentsChanged : Event < EnvironmentsChangedParams [ ] > ;
56
+ onDidChangeEnvironments : Event < EnvironmentsChangedParams [ ] > ;
65
57
/**
66
58
* This API will re-trigger environment discovery. Extensions can wait on the returned
67
59
* promise to get the updated environment list. If there is a refresh already going on
@@ -70,12 +62,12 @@ export interface IProposedExtensionAPI {
70
62
* * clearCache : When true, this will clear the cache before environment refresh
71
63
* is triggered.
72
64
*/
73
- refreshEnvironments ( options ?: RefreshEnvironmentsOptions ) : Promise < EnvPathType [ ] | undefined > ;
65
+ refreshEnvironments ( options ?: RefreshEnvironmentsOptions ) : Promise < EnvironmentPath [ ] | undefined > ;
74
66
/**
75
67
* Returns a promise for the ongoing refresh. Returns `undefined` if there are no active
76
68
* refreshes going on.
77
69
*/
78
- getRefreshPromise ( options ?: GetRefreshEnvironmentsOptions ) : Promise < void > | undefined ;
70
+ getRefreshPromise ( options ?: GetRefreshPromiseOptions ) : Promise < void > | undefined ;
79
71
/**
80
72
* Tracks discovery progress for current list of known environments, i.e when it starts, finishes or any other relevant
81
73
* stage. Note the progress for a particular query is currently not tracked or reported, this only indicates progress of
@@ -92,26 +84,11 @@ export enum Architecture {
92
84
x64 = 3 ,
93
85
}
94
86
95
- export type EnvSource = KnownEnvSourceTypes | string ;
96
-
97
- export enum KnownEnvSourceTypes {
98
- Conda = 'Conda' ,
99
- Pipenv = 'PipEnv' ,
100
- Poetry = 'Poetry' ,
101
- VirtualEnv = 'VirtualEnv' ,
102
- Venv = 'Venv' ,
103
- VirtualEnvWrapper = 'VirtualEnvWrapper' ,
104
- Pyenv = 'Pyenv' ,
105
- }
87
+ export type EnvSource = KnownEnvSources | string ;
88
+ export type KnownEnvSources = 'Conda' | 'Pipenv' | 'Poetry' | 'VirtualEnv' | 'Venv' | 'VirtualEnvWrapper' | 'Pyenv' ;
106
89
107
90
export type EnvType = KnownEnvTypes | string ;
108
-
109
- export enum KnownEnvTypes {
110
- VirtualEnv = 'VirtualEnv' ,
111
- Conda = 'Conda' ,
112
- Unknown = 'Unknown' ,
113
- Global = 'Global' ,
114
- }
91
+ export type KnownEnvTypes = 'VirtualEnv' | 'Conda' | 'Unknown' ;
115
92
116
93
export type BasicVersionInfo = {
117
94
major : number ;
@@ -141,27 +118,35 @@ export type StandardVersionInfo = BasicVersionInfo & {
141
118
release ?: PythonVersionRelease ;
142
119
} ;
143
120
121
+ // To be added later:
122
+ // run: {
123
+ // exec: Function;
124
+ // shellExec: Function;
125
+ // execObservable: Function;
126
+ // terminalExec: () => void;
127
+ // env?: { [key: string]: string | null | undefined };
128
+ // };
129
+
144
130
export interface EnvironmentDetails {
145
131
executable : {
146
132
path : string ;
147
133
bitness ?: Architecture ;
148
134
sysPrefix : string ;
149
- // To be added later:
150
- // run: {
151
- // exec: Function;
152
- // shellExec: Function;
153
- // execObservable: Function;
154
- // terminalExec: () => void;
155
- // env?: { [key: string]: string | null | undefined };
156
- // };
157
- } ;
158
- environment ?: {
159
- type : EnvType ;
160
- name ?: string ;
161
- path : string ;
162
- project ?: string ; // Any specific project environment is created for.
163
- source : EnvSource [ ] ;
164
135
} ;
136
+ environment :
137
+ | {
138
+ type : EnvType ;
139
+ name ?: string ;
140
+ path : string ;
141
+ /**
142
+ * Any specific workspace folder this environment is created for.
143
+ * What if that workspace folder is not opened yet? We should still provide a workspace folder so it can be filtered out.
144
+ * WorkspaceFolder type won't work as it assumes the workspace is opened, hence using URI.
145
+ */
146
+ workspaceFolder ?: Uri ;
147
+ source : EnvSource [ ] ;
148
+ }
149
+ | undefined ;
165
150
version : StandardVersionInfo & {
166
151
sysVersion ?: string ;
167
152
} ;
@@ -173,10 +158,13 @@ export interface EnvironmentDetails {
173
158
}
174
159
175
160
export interface EnvironmentDetailsOptions {
161
+ /**
162
+ * When true, cache is checked first for any data, returns even if there is partial data.
163
+ */
176
164
useCache : boolean ;
177
165
}
178
166
179
- export interface GetRefreshEnvironmentsOptions {
167
+ export interface GetRefreshPromiseOptions {
180
168
/**
181
169
* Get refresh promise which resolves once the following stage has been reached for the list of known environments.
182
170
*/
@@ -193,30 +181,55 @@ export type ProgressNotificationEvent = {
193
181
stage : ProgressReportStage ;
194
182
} ;
195
183
196
- export type Resource = Uri | undefined ;
184
+ /**
185
+ * Uri of a file inside a workspace or workspace folder itself.
186
+ */
187
+ export type Resource = Uri | WorkspaceFolder ;
197
188
198
189
/**
199
- * Path to environment folder or path to interpreter that uniquely identifies an environment.
200
- * Environments lacking an interpreter are identified by environment folder paths,
201
- * whereas other envs can be identified using interpreter path.
190
+ * Path to environment folder or path to python executable that uniquely identifies an environment.
191
+ * Environments lacking a python executable are identified by environment folder paths,
192
+ * whereas other envs can be identified using python executable path.
202
193
*/
203
194
export type UniquePathType = string ;
204
195
205
- export interface EnvPathType {
206
- path : UniquePathType ;
207
- pathType : 'envFolderPath' | 'interpreterPath' ;
196
+ export interface EnvironmentPath {
197
+ pathID : UniquePathType ;
198
+ /**
199
+ * Path to python executable that uniquely identifies an environment.
200
+ * Carries `undefined` if an executable cannot uniquely identify an
201
+ * environment or does not exist within the env.
202
+ */
203
+ executablePath : string | undefined ;
208
204
}
209
205
210
206
export interface EnvironmentsChangedParams {
211
- path ?: UniquePathType ;
207
+ pathID ?: UniquePathType ;
208
+ /**
209
+ * Types:
210
+ * * "add": New environment is added.
211
+ * * "remove": Existing environment in the list is removed.
212
+ * * "update": New information found about existing environment.
213
+ * * "clear-all": Remove all of the items in the list. (This is fired when a hard refresh is triggered)
214
+ */
212
215
type : 'add' | 'remove' | 'update' | 'clear-all' ;
213
216
}
214
217
215
218
export interface ActiveEnvironmentChangedParams {
216
- path : UniquePathType ;
217
- resource ?: Uri ;
219
+ pathID : UniquePathType ;
220
+ /**
221
+ * Uri of a file inside a workspace or workspace folder the environment changed for.
222
+ */
223
+ resource ?: Resource ;
218
224
}
219
225
220
226
export interface RefreshEnvironmentsOptions {
227
+ /**
228
+ * When `true`, this will clear the cache before environment refresh is triggered.
229
+ */
221
230
clearCache ?: boolean ;
231
+ /**
232
+ * Only trigger a refresh if it hasn't already been triggered for this session.
233
+ */
234
+ ifNotTriggerredAlready ?: boolean ;
222
235
}
0 commit comments