Skip to content

Commit e572f08

Browse files
docs: add @remarks to EnvironmentManager interface documenting when each method is called (#1437)
## Summary Adds `@remarks` JSDoc sections to all methods on the `EnvironmentManager` interface, documenting **which user actions or internal events trigger each method**. Changes are documentation-only — no functional changes. ## Motivation Raised in #378: third-party extension authors implementing `EnvironmentManager` know *what* each method does (the existing JSDoc covers that), but not *when* or *why* it gets called. For example, `get()` is described as "retrieves the current Python environment" — but there's no mention that it's called at extension startup, during terminal activation, before script execution, etc. This makes it hard for authors to reason about their implementation. They end up guessing at lifecycle behavior, which leads to bugs (e.g., not caching in `get()` because they didn't realize it's called frequently). ## What's added `@remarks` sections on 8 methods of `EnvironmentManager` in both `src/api.ts` and `pythonEnvironmentsApi/src/main.ts`: | Method | Trigger summary | |--------|----------------| | `create` | "Create Environment" command, "+" button in tree view, new package project wizard | | `remove` | Right-click → "Delete Environment" in tree view | | `refresh` | Refresh button in the Python Environments view title bar | | `getEnvironments` | Tree view expansion, environment picker, internally after `refresh` | | `set` | Environment picker selection, checkmark button in tree view, auto-select after create, startup caching, project removal | | `get` | Startup, after `set`, terminal activation, script execution, picker display, auto-discovery | | `resolve` | File picker interpreter selection, `defaultInterpreterPath` resolution, pre-run resolution | | `clearCache` | "Python: Clear Cache" command | Each remark was verified by tracing every call site through `InternalEnvironmentManager` → `envManagers.ts` → `envCommands.ts` → `extension.ts` command registrations and `package.json` menu contributions. ## Who this helps Extension authors building environment managers for tools like Hatch, Pixi, uv, etc. They can now hover over any `EnvironmentManager` method in their IDE and see exactly what user actions will invoke it, making implementation decisions much clearer. ## Files changed - `src/api.ts` — internal API copy (+45 lines, documentation only) - `pythonEnvironmentsApi/src/main.ts` — published API package (+45 lines, documentation only) Refs #378 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 69be6a4 commit e572f08

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

pythonEnvironmentsApi/src/main.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ export interface QuickCreateConfig {
343343

344344
/**
345345
* Interface representing an environment manager.
346+
*
347+
* @remarks
348+
* Methods on this interface are invoked both by the Python Environments extension itself
349+
* (in response to UI actions, startup, terminal activation, script execution, and so on)
350+
* and directly by other extensions that consume the published API. Any "called when…"
351+
* notes on individual methods list representative triggers only — they are not
352+
* exhaustive, and the precise set of call sites may evolve over time. Implementations
353+
* should focus on the documented contract rather than any specific caller.
346354
*/
347355
export interface EnvironmentManager {
348356
/**
@@ -396,27 +404,44 @@ export interface EnvironmentManager {
396404
* @param scope - The scope within which to create the environment.
397405
* @param options - Optional parameters for creating the Python environment.
398406
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
407+
*
408+
* @remarks
409+
* Invoked when an environment of this manager's type should be created for the given
410+
* scope. Typical triggers include user-initiated environment-creation flows and
411+
* programmatic creation via the API.
399412
*/
400413
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
401414

402415
/**
403416
* Removes the specified Python environment.
404417
* @param environment - The Python environment to remove.
405418
* @returns A promise that resolves when the environment is removed.
419+
*
420+
* @remarks
421+
* Invoked to delete the given environment. Typical triggers include an explicit user
422+
* action (such as a "Delete Environment" command) and programmatic removal via the API.
406423
*/
407424
remove?(environment: PythonEnvironment): Promise<void>;
408425

409426
/**
410427
* Refreshes the list of Python environments within the specified scope.
411428
* @param scope - The scope within which to refresh environments.
412429
* @returns A promise that resolves when the refresh is complete.
430+
*
431+
* @remarks
432+
* Forces the manager to re-discover environments for the given scope. Typically
433+
* triggered by an explicit user "refresh" action.
413434
*/
414435
refresh(scope: RefreshEnvironmentsScope): Promise<void>;
415436

416437
/**
417438
* Retrieves a list of Python environments within the specified scope.
418439
* @param scope - The scope within which to retrieve environments.
419440
* @returns A promise that resolves to an array of Python environments.
441+
*
442+
* @remarks
443+
* Returns the environments known to this manager for the given scope. Called
444+
* frequently by UI surfaces (tree views, pickers) and by other consumers of the API.
420445
*/
421446
getEnvironments(scope: GetEnvironmentsScope): Promise<PythonEnvironment[]>;
422447

@@ -430,13 +455,27 @@ export interface EnvironmentManager {
430455
* @param scope - The scope within which to set the environment.
431456
* @param environment - The Python environment to set. If undefined, the environment is unset.
432457
* @returns A promise that resolves when the environment is set.
458+
*
459+
* @remarks
460+
* Invoked when the active environment for the given scope should change — for example
461+
* after the user selects an environment in a picker, after a newly created environment
462+
* is auto-selected, or programmatically via the API.
463+
*
464+
* Also invoked at extension startup to rehydrate the active environment from
465+
* persisted state.
433466
*/
434467
set(scope: SetEnvironmentScope, environment?: PythonEnvironment): Promise<void>;
435468

436469
/**
437470
* Retrieves the current Python environment within the specified scope.
438471
* @param scope - The scope within which to retrieve the environment.
439472
* @returns A promise that resolves to the current Python environment, or undefined if none is set.
473+
*
474+
* @remarks
475+
* Returns the currently active environment for the given scope, or `undefined` if
476+
* none is selected. Called very frequently — at startup, after {@link set}, when a
477+
* terminal is opened, before running Python, by UI surfaces that display the active
478+
* interpreter, and by other extensions consuming the API.
440479
*/
441480
get(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined>;
442481

@@ -456,13 +495,27 @@ export interface EnvironmentManager {
456495
*
457496
* @param context - The context for resolving the environment, which can be a {@link PythonEnvironment} or a {@link Uri}.
458497
* @returns A promise that resolves to the fully detailed {@link PythonEnvironment}, or `undefined` if the environment cannot be resolved.
498+
*
499+
* @remarks
500+
* Called to turn a lightly-populated {@link PythonEnvironment} or a {@link Uri}
501+
* pointing at an interpreter or environment folder into a fully-populated
502+
* {@link PythonEnvironment} with complete {@link PythonEnvironment.execInfo}. Typical
503+
* triggers include the user manually selecting an interpreter path, resolving
504+
* `python.defaultInterpreterPath` at startup, and populating execution details before
505+
* launching Python.
459506
*/
460507
resolve(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;
461508

462509
/**
463510
* Clears the environment manager's cache.
464511
*
465512
* @returns A promise that resolves when the cache is cleared.
513+
*
514+
* @remarks
515+
* Drops any cached environment data held by the manager so that subsequent calls to
516+
* {@link EnvironmentManager.getEnvironments} or {@link EnvironmentManager.get}
517+
* re-discover state from disk. Typically triggered by an explicit user "clear cache"
518+
* action.
466519
*/
467520
clearCache?(): Promise<void>;
468521
}

src/api.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ export interface QuickCreateConfig {
337337

338338
/**
339339
* Interface representing an environment manager.
340+
*
341+
* @remarks
342+
* Methods on this interface are invoked both by the Python Environments extension itself
343+
* (in response to UI actions, startup, terminal activation, script execution, and so on)
344+
* and directly by other extensions that consume the published API. Any "called when…"
345+
* notes on individual methods list representative triggers only — they are not
346+
* exhaustive, and the precise set of call sites may evolve over time. Implementations
347+
* should focus on the documented contract rather than any specific caller.
340348
*/
341349
export interface EnvironmentManager {
342350
/**
@@ -390,27 +398,44 @@ export interface EnvironmentManager {
390398
* @param scope - The scope within which to create the environment.
391399
* @param options - Optional parameters for creating the Python environment.
392400
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
401+
*
402+
* @remarks
403+
* Invoked when an environment of this manager's type should be created for the given
404+
* scope. Typical triggers include user-initiated environment-creation flows and
405+
* programmatic creation via the API.
393406
*/
394407
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
395408

396409
/**
397410
* Removes the specified Python environment.
398411
* @param environment - The Python environment to remove.
399412
* @returns A promise that resolves when the environment is removed.
413+
*
414+
* @remarks
415+
* Invoked to delete the given environment. Typical triggers include an explicit user
416+
* action (such as a "Delete Environment" command) and programmatic removal via the API.
400417
*/
401418
remove?(environment: PythonEnvironment): Promise<void>;
402419

403420
/**
404421
* Refreshes the list of Python environments within the specified scope.
405422
* @param scope - The scope within which to refresh environments.
406423
* @returns A promise that resolves when the refresh is complete.
424+
*
425+
* @remarks
426+
* Forces the manager to re-discover environments for the given scope. Typically
427+
* triggered by an explicit user "refresh" action.
407428
*/
408429
refresh(scope: RefreshEnvironmentsScope): Promise<void>;
409430

410431
/**
411432
* Retrieves a list of Python environments within the specified scope.
412433
* @param scope - The scope within which to retrieve environments.
413434
* @returns A promise that resolves to an array of Python environments.
435+
*
436+
* @remarks
437+
* Returns the environments known to this manager for the given scope. Called
438+
* frequently by UI surfaces (tree views, pickers) and by other consumers of the API.
414439
*/
415440
getEnvironments(scope: GetEnvironmentsScope): Promise<PythonEnvironment[]>;
416441

@@ -424,13 +449,27 @@ export interface EnvironmentManager {
424449
* @param scope - The scope within which to set the environment.
425450
* @param environment - The Python environment to set. If undefined, the environment is unset.
426451
* @returns A promise that resolves when the environment is set.
452+
*
453+
* @remarks
454+
* Invoked when the active environment for the given scope should change — for example
455+
* after the user selects an environment in a picker, after a newly created environment
456+
* is auto-selected, or programmatically via the API.
457+
*
458+
* Also invoked at extension startup to rehydrate the active environment from
459+
* persisted state.
427460
*/
428461
set(scope: SetEnvironmentScope, environment?: PythonEnvironment): Promise<void>;
429462

430463
/**
431464
* Retrieves the current Python environment within the specified scope.
432465
* @param scope - The scope within which to retrieve the environment.
433466
* @returns A promise that resolves to the current Python environment, or undefined if none is set.
467+
*
468+
* @remarks
469+
* Returns the currently active environment for the given scope, or `undefined` if
470+
* none is selected. Called very frequently — at startup, after {@link set}, when a
471+
* terminal is opened, before running Python, by UI surfaces that display the active
472+
* interpreter, and by other extensions consuming the API.
434473
*/
435474
get(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined>;
436475

@@ -450,13 +489,27 @@ export interface EnvironmentManager {
450489
*
451490
* @param context - The context for resolving the environment, which can be a {@link PythonEnvironment} or a {@link Uri}.
452491
* @returns A promise that resolves to the fully detailed {@link PythonEnvironment}, or `undefined` if the environment cannot be resolved.
492+
*
493+
* @remarks
494+
* Called to turn a lightly-populated {@link PythonEnvironment} or a {@link Uri}
495+
* pointing at an interpreter or environment folder into a fully-populated
496+
* {@link PythonEnvironment} with complete {@link PythonEnvironment.execInfo}. Typical
497+
* triggers include the user manually selecting an interpreter path, resolving
498+
* `python.defaultInterpreterPath` at startup, and populating execution details before
499+
* launching Python.
453500
*/
454501
resolve(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;
455502

456503
/**
457504
* Clears the environment manager's cache.
458505
*
459506
* @returns A promise that resolves when the cache is cleared.
507+
*
508+
* @remarks
509+
* Drops any cached environment data held by the manager so that subsequent calls to
510+
* {@link EnvironmentManager.getEnvironments} or {@link EnvironmentManager.get}
511+
* re-discover state from disk. Typically triggered by an explicit user "clear cache"
512+
* action.
460513
*/
461514
clearCache?(): Promise<void>;
462515
}

0 commit comments

Comments
 (0)