docs: add @remarks to EnvironmentManager interface documenting when each method is called#1437
docs: add @remarks to EnvironmentManager interface documenting when each method is called#1437StellaHuang95 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
will review - sorry for the delay |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds @remarks documentation to the EnvironmentManager interface to clarify which user actions / internal events trigger each method, helping third-party implementers understand lifecycle and call frequency.
Changes:
- Added
@remarkssections for 8EnvironmentManagermethods describing triggering UI actions and internal flows. - Mirrored the same documentation in both the internal (
src/api.ts) and published (pythonEnvironmentsApi/src/main.ts) API surfaces.
Show a summary per file
| File | Description |
|---|---|
| src/api.ts | Adds @remarks to EnvironmentManager methods documenting when each is invoked. |
| pythonEnvironmentsApi/src/main.ts | Mirrors the same @remarks additions for the published API package. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 3
| * - Runs the "Python: Create Environment" command (which prompts for a manager to use). | ||
| * - Clicks the "+" button on an environment manager in the Python Environments view. | ||
| * - Creates a new environment as part of the new Python package project creation wizard. |
There was a problem hiding this comment.
The new remarks rely on exact UI labels/symbols (e.g., command palette text, "+" button) which can change over time and may be localized. Consider referencing stable identifiers instead (e.g., command IDs like python.createEnvironment, view IDs, or contribution points such as package.json command/menu entries) and phrasing UI triggers more generically (e.g., “the Create Environment command” / “the add-environment action in the Python Environments view”). This will make the docs more resilient and less likely to become stale.
| * - Runs the "Python: Create Environment" command (which prompts for a manager to use). | |
| * - Clicks the "+" button on an environment manager in the Python Environments view. | |
| * - Creates a new environment as part of the new Python package project creation wizard. | |
| * - Invokes the `python.createEnvironment` command (which prompts for a manager to use). | |
| * - Uses the add-environment action for an environment manager in the Python Environments view. | |
| * - Creates a new environment as part of a Python package project creation flow. |
| * Also called at extension startup during initial environment selection to cache the active | ||
| * environment, and when a Python project is removed (with `environment` set to `undefined`). |
There was a problem hiding this comment.
The remark “called…to cache the active environment” could be read as suggesting set() is used for caching rather than state changes. To reduce ambiguity for implementers, consider clarifying expected semantics at startup (e.g., that set() may be invoked with the already-persisted/previously-selected environment and should be treated as idempotent, potentially firing change events only when the selection actually changes). This helps implementers avoid doing unnecessary work or producing side effects on startup.
| * Also called at extension startup during initial environment selection to cache the active | |
| * environment, and when a Python project is removed (with `environment` set to `undefined`). | |
| * Also called at extension startup during initial environment selection to initialize or | |
| * reconcile the active environment state. This startup call may pass the already-persisted or | |
| * previously-selected environment; implementations should treat it as idempotent and avoid | |
| * unnecessary work or side effects, including firing change events, unless the selected | |
| * environment actually changes. Also called when a Python project is removed (with | |
| * `environment` set to `undefined`). |
| * @remarks | ||
| * Called when the user: | ||
| * - Runs the "Python: Create Environment" command (which prompts for a manager to use). | ||
| * - Clicks the "+" button on an environment manager in the Python Environments view. | ||
| * - Creates a new environment as part of the new Python package project creation wizard. |
There was a problem hiding this comment.
This PR intentionally duplicates substantial documentation across src/api.ts and pythonEnvironmentsApi/src/main.ts. Since these two interface definitions must stay in sync, the added @remarks increases the risk of divergence over time. If feasible in this repo, consider centralizing the EnvironmentManager type (or generating the published API from the internal source) so the docs live in a single place and are re-exported/shared, reducing future maintenance burden.
Summary
Adds
@remarksJSDoc sections to all methods on theEnvironmentManagerinterface, 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
EnvironmentManagerknow 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
@remarkssections on 8 methods ofEnvironmentManagerin bothsrc/api.tsandpythonEnvironmentsApi/src/main.ts:createremoverefreshgetEnvironmentsrefreshsetgetset, terminal activation, script execution, picker display, auto-discoveryresolvedefaultInterpreterPathresolution, pre-run resolutionclearCacheEach remark was verified by tracing every call site through
InternalEnvironmentManager→envManagers.ts→envCommands.ts→extension.tscommand registrations andpackage.jsonmenu contributions.Who this helps
Extension authors building environment managers for tools like Hatch, Pixi, uv, etc. They can now hover over any
EnvironmentManagermethod 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