You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: api/README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,3 +35,20 @@ export async function activate() {
35
35
}
36
36
```
37
37
38
+
## Full API reference
39
+
40
+
📘 **[Python Environments API reference](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md)**
41
+
42
+
The complete manual documents every method and data type, organized by domain -
43
+
environments, packages, projects, execution, environment variables, and
44
+
extensibility - with field tables, parameter tables, return types, and examples.
45
+
46
+
-[Environments](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md#environments) - discover, resolve, select, create, and remove interpreters
47
+
-[Packages](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md#packages) - list, install, uninstall, and look up versions
48
+
-[Projects](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md#projects) - the folders the extension tracks
49
+
-[Execution](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md#execution) - run Python in terminals, tasks, and background processes
50
+
-[Environment variables](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md#environment-variables) - resolved variables for a scope
51
+
-[Extensibility](https://github.com/microsoft/vscode-python-environments/blob/main/docs/README.md#extensibility) - register your own environment manager, package manager, or project creator
52
+
53
+
See [`CHANGELOG.md`](https://github.com/microsoft/vscode-python-environments/blob/main/api/CHANGELOG.md) for API changes between versions.
|`scope`|[`RefreshEnvironmentsScope`](#scope-types)| Yes (may be `undefined`) |`Uri` refreshes discovery for that project or folder; `undefined` refreshes global and workspace discovery. |
381
381
382
-
**Returns**`Promise<void>`, resolving when discovery completes. Results arrive
383
-
through [`onDidChangeEnvironments`](#ondidchangeenvironments); subscribe before
384
-
refreshing if you need the deltas.
382
+
**Returns**`Promise<void>`, resolving when the managers finish discovery.
383
+
384
+
Read the results with [`getEnvironments`](#getenvironments) once the promise
385
+
settles. Do not rely on [`onDidChangeEnvironments`](#ondidchangeenvironments)
386
+
to deliver them: that event is optional on `EnvironmentManager`, and
387
+
`refreshEnvironments` does not synthesize one, so whether a refresh produces
388
+
deltas is up to the provider.
385
389
386
390
```typescript
387
391
awaitapi.refreshEnvironments(undefined);
392
+
// Authoritative: read the list rather than waiting for an event.
388
393
const refreshed =awaitapi.getEnvironments('all');
389
394
```
390
395
@@ -439,6 +444,29 @@ const active = await api.getEnvironment(
439
444
);
440
445
```
441
446
447
+
> [!IMPORTANT]
448
+
> **This call can return a stale value.** It is deliberately non-blocking: it
449
+
> races the real resolution against a one-second timeout so that slow initial
450
+
> discovery cannot stall callers. If resolution has not finished in time, it
451
+
> returns the *last-known* environment for the scope - which may be `undefined`
452
+
> on a first call - while resolution continues in the background.
453
+
>
454
+
> The resolved value is published through
455
+
> [`onDidChangeEnvironment`](#ondidchangeenvironment) once it settles. If your
456
+
> feature needs the authoritative selection, subscribe to that event and treat
457
+
> the value from `getEnvironment` as a fast first guess:
458
+
>
459
+
> ```typescript
460
+
>let current =awaitapi.getEnvironment(projectUri); // May be last-known.
|`name`|`string`| Yes | Name of the task, shown in the task UI. |
1237
1265
|`args`|`string[]`| Yes | Arguments passed to the Python executable. |
1238
1266
|`project`|[`PythonProject`](#pythonproject)| No | Project the task belongs to. |
1239
-
|`cwd`|`string`| No | Working directory. Defaults to the project directory of the script being run. |
1267
+
|`cwd`|`string`| No | Working directory for the task's shell execution. When omitted, VS Code resolves it from the task scope - the workspace folder containing `project`, or the global scope when `project` is not supplied. |
1240
1268
|`env`|`{ [key: string]: string }`| No | Additional environment variables for the task. |
1241
1269
1242
1270
#### `PythonBackgroundRunOptions`
1243
1271
1244
1272
| Field | Type | Required | Description |
1245
1273
| --- | --- | --- | --- |
1246
1274
|`args`|`string[]`| Yes | Arguments passed to the Python executable. |
1247
-
|`cwd`|`string`| No | Working directory. Defaults to the project directory of the script being run. |
1275
+
|`cwd`|`string`| No | Working directory, passed straight to the spawned process. When omitted, the process inherits the extension host's working directory, which is **not** your project folder - always supply `cwd` (for example `project.uri.fsPath`) if the script resolves relative paths. |
1248
1276
|`env`|`{ [key: string]: string \| undefined }`| No | Additional environment variables. An `undefined` value unsets a variable. |
1249
1277
1250
1278
#### `PythonProcess`
@@ -1391,11 +1419,20 @@ runInBackground(
1391
1419
| Parameter | Type | Required | Description |
1392
1420
| --- | --- | --- | --- |
1393
1421
|`environment`|[`PythonEnvironment`](#pythonenvironment)| Yes | Environment used to start the process. |
1394
-
|`options`|[`PythonBackgroundRunOptions`](#pythonbackgroundrunoptions)| Yes |`args` for Python, plus optional `cwd` and `env`. |
1422
+
|`options`|[`PythonBackgroundRunOptions`](#pythonbackgroundrunoptions)| Yes |`args` for Python, plus optional `cwd` and `env`. Supply `cwd` - it is not inferred. |
1395
1423
1396
1424
**Returns**`Promise<PythonProcess>` with `stdin`, `stdout`, `stderr`, `kill()`,
1397
1425
and `onExit()`.
1398
1426
1427
+
> [!IMPORTANT]
1428
+
> `cwd` is forwarded to the spawned process unchanged. There is no project
1429
+
> context to infer it from, so when you omit it the process inherits the
1430
+
> extension host's working directory rather than your project folder. Pass
1431
+
> `cwd` explicitly whenever the script resolves relative paths.
1432
+
>
1433
+
> You own the process lifetime: call `kill()` when your feature is done, and
1434
+
> tie it to your disposables so it does not outlive deactivation.
0 commit comments