Skip to content

Commit 7de08fb

Browse files
committed
address feedback
1 parent 3251861 commit 7de08fb

2 files changed

Lines changed: 72 additions & 64 deletions

File tree

pythonEnvironmentsApi/src/main.ts

Lines changed: 36 additions & 32 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
/**
@@ -398,10 +406,9 @@ export interface EnvironmentManager {
398406
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
399407
*
400408
* @remarks
401-
* Called when the user:
402-
* - Invokes the `python.createEnvironment` command (which prompts for a manager to use).
403-
* - Uses the add-environment action for an environment manager in the Python Environments view.
404-
* - Creates a new environment as part of a Python package project creation flow.
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.
405412
*/
406413
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
407414

@@ -411,8 +418,8 @@ export interface EnvironmentManager {
411418
* @returns A promise that resolves when the environment is removed.
412419
*
413420
* @remarks
414-
* Called when the user right-clicks an environment in the Python Environments tree view and selects
415-
* "Delete Environment".
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.
416423
*/
417424
remove?(environment: PythonEnvironment): Promise<void>;
418425

@@ -422,7 +429,8 @@ export interface EnvironmentManager {
422429
* @returns A promise that resolves when the refresh is complete.
423430
*
424431
* @remarks
425-
* Called when the user clicks the refresh button in the Python Environments view title bar.
432+
* Forces the manager to re-discover environments for the given scope. Typically
433+
* triggered by an explicit user "refresh" action.
426434
*/
427435
refresh(scope: RefreshEnvironmentsScope): Promise<void>;
428436

@@ -432,10 +440,8 @@ export interface EnvironmentManager {
432440
* @returns A promise that resolves to an array of Python environments.
433441
*
434442
* @remarks
435-
* Called when:
436-
* - The user expands an environment manager node in the Python Environments tree view.
437-
* - The user opens the environment picker to select an interpreter.
438-
* - Internally after {@link EnvironmentManager.refresh} completes, to count discovered environments.
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.
439445
*/
440446
getEnvironments(scope: GetEnvironmentsScope): Promise<PythonEnvironment[]>;
441447

@@ -451,16 +457,12 @@ export interface EnvironmentManager {
451457
* @returns A promise that resolves when the environment is set.
452458
*
453459
* @remarks
454-
* Called when the user:
455-
* - Selects an environment in the environment picker or clicks the checkmark button in the tree view.
456-
* - Creates a new environment and the extension auto-selects it.
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.
457463
*
458-
* Also called at extension startup during initial environment selection to initialize or
459-
* reconcile the active environment state. This startup call may pass the already-persisted or
460-
* previously-selected environment; implementations should treat it as idempotent and avoid
461-
* unnecessary work or side effects, including firing change events, unless the selected
462-
* environment actually changes. Also called when a Python project is removed (with
463-
* `environment` set to `undefined`).
464+
* Also invoked at extension startup to rehydrate the active environment from
465+
* persisted state.
464466
*/
465467
set(scope: SetEnvironmentScope, environment?: PythonEnvironment): Promise<void>;
466468

@@ -470,13 +472,10 @@ export interface EnvironmentManager {
470472
* @returns A promise that resolves to the current Python environment, or undefined if none is set.
471473
*
472474
* @remarks
473-
* Called when:
474-
* - The extension starts up, during initial environment selection for each workspace folder and global scope.
475-
* - After {@link EnvironmentManager.set}, to confirm the new active environment and fire change events.
476-
* - A terminal is opened or a command is run, to determine which Python environment to activate.
477-
* - The user runs a Python file ("Run in Terminal", "Run as Task"), to get the interpreter.
478-
* - The environment picker needs to display the currently selected (recommended) environment.
479-
* - Auto-discovery checks if a local venv already exists for a workspace folder.
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.
480479
*/
481480
get(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined>;
482481

@@ -498,10 +497,12 @@ export interface EnvironmentManager {
498497
* @returns A promise that resolves to the fully detailed {@link PythonEnvironment}, or `undefined` if the environment cannot be resolved.
499498
*
500499
* @remarks
501-
* Called when:
502-
* - The user browses for and selects a Python interpreter path via the file picker.
503-
* - The user has `python.defaultInterpreterPath` configured and the extension resolves it at startup.
504-
* - Before running a Python script ("Run in Terminal", "Run as Task"), to obtain full execution info.
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.
505506
*/
506507
resolve(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;
507508

@@ -511,7 +512,10 @@ export interface EnvironmentManager {
511512
* @returns A promise that resolves when the cache is cleared.
512513
*
513514
* @remarks
514-
* Called when the user runs the "Python: Clear Cache" command from the Command Palette.
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.
515519
*/
516520
clearCache?(): Promise<void>;
517521
}

src/api.ts

Lines changed: 36 additions & 32 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
/**
@@ -392,10 +400,9 @@ export interface EnvironmentManager {
392400
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
393401
*
394402
* @remarks
395-
* Called when the user:
396-
* - Invokes the `python.createEnvironment` command (which prompts for a manager to use).
397-
* - Uses the add-environment action for an environment manager in the Python Environments view.
398-
* - Creates a new environment as part of a Python package project creation flow.
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.
399406
*/
400407
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
401408

@@ -405,8 +412,8 @@ export interface EnvironmentManager {
405412
* @returns A promise that resolves when the environment is removed.
406413
*
407414
* @remarks
408-
* Called when the user right-clicks an environment in the Python Environments tree view and selects
409-
* "Delete Environment".
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.
410417
*/
411418
remove?(environment: PythonEnvironment): Promise<void>;
412419

@@ -416,7 +423,8 @@ export interface EnvironmentManager {
416423
* @returns A promise that resolves when the refresh is complete.
417424
*
418425
* @remarks
419-
* Called when the user clicks the refresh button in the Python Environments view title bar.
426+
* Forces the manager to re-discover environments for the given scope. Typically
427+
* triggered by an explicit user "refresh" action.
420428
*/
421429
refresh(scope: RefreshEnvironmentsScope): Promise<void>;
422430

@@ -426,10 +434,8 @@ export interface EnvironmentManager {
426434
* @returns A promise that resolves to an array of Python environments.
427435
*
428436
* @remarks
429-
* Called when:
430-
* - The user expands an environment manager node in the Python Environments tree view.
431-
* - The user opens the environment picker to select an interpreter.
432-
* - Internally after {@link EnvironmentManager.refresh} completes, to count discovered environments.
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.
433439
*/
434440
getEnvironments(scope: GetEnvironmentsScope): Promise<PythonEnvironment[]>;
435441

@@ -445,16 +451,12 @@ export interface EnvironmentManager {
445451
* @returns A promise that resolves when the environment is set.
446452
*
447453
* @remarks
448-
* Called when the user:
449-
* - Selects an environment in the environment picker or clicks the checkmark button in the tree view.
450-
* - Creates a new environment and the extension auto-selects it.
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.
451457
*
452-
* Also called at extension startup during initial environment selection to initialize or
453-
* reconcile the active environment state. This startup call may pass the already-persisted or
454-
* previously-selected environment; implementations should treat it as idempotent and avoid
455-
* unnecessary work or side effects, including firing change events, unless the selected
456-
* environment actually changes. Also called when a Python project is removed (with
457-
* `environment` set to `undefined`).
458+
* Also invoked at extension startup to rehydrate the active environment from
459+
* persisted state.
458460
*/
459461
set(scope: SetEnvironmentScope, environment?: PythonEnvironment): Promise<void>;
460462

@@ -464,13 +466,10 @@ export interface EnvironmentManager {
464466
* @returns A promise that resolves to the current Python environment, or undefined if none is set.
465467
*
466468
* @remarks
467-
* Called when:
468-
* - The extension starts up, during initial environment selection for each workspace folder and global scope.
469-
* - After {@link EnvironmentManager.set}, to confirm the new active environment and fire change events.
470-
* - A terminal is opened or a command is run, to determine which Python environment to activate.
471-
* - The user runs a Python file ("Run in Terminal", "Run as Task"), to get the interpreter.
472-
* - The environment picker needs to display the currently selected (recommended) environment.
473-
* - Auto-discovery checks if a local venv already exists for a workspace folder.
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.
474473
*/
475474
get(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined>;
476475

@@ -492,10 +491,12 @@ export interface EnvironmentManager {
492491
* @returns A promise that resolves to the fully detailed {@link PythonEnvironment}, or `undefined` if the environment cannot be resolved.
493492
*
494493
* @remarks
495-
* Called when:
496-
* - The user browses for and selects a Python interpreter path via the file picker.
497-
* - The user has `python.defaultInterpreterPath` configured and the extension resolves it at startup.
498-
* - Before running a Python script ("Run in Terminal", "Run as Task"), to obtain full execution info.
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.
499500
*/
500501
resolve(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;
501502

@@ -505,7 +506,10 @@ export interface EnvironmentManager {
505506
* @returns A promise that resolves when the cache is cleared.
506507
*
507508
* @remarks
508-
* Called when the user runs the "Python: Clear Cache" command from the Command Palette.
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.
509513
*/
510514
clearCache?(): Promise<void>;
511515
}

0 commit comments

Comments
 (0)