Watch package changes through PackageWatcher instead of TerminaPacakageWatcher - #1698
Conversation
|
🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR. |
|
GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for src/features/terminal/terminalPackageWatcher.ts:L1.
Removing this watcher drops refreshes for environments manually activated in a terminal but not selected in any workspace scope. Please confirm that this behavior is intentionally out of scope for #1683 and document the tradeoff in the PR description. |
| "integrity": "sha512-D7DbgGFtsqIPIFMPJwCad9Gfi/hC0PWErRRHFnaCWoEDYi5tQUDiJCTmGUbBiLzjqAck4KcXt9Ayj0CNlIrF+w==", | ||
| "dev": true, | ||
| "license": "BSD-2-Clause", | ||
| "peer": true, |
There was a problem hiding this comment.
Info · Optional note
These "peer": true additions appear unrelated to the watcher refactor and look like incidental lockfile reserialization. Please revert this churn to keep the change focused.
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
| log: LogOutputChannel, | ||
| ): Disposable { | ||
| // Watch targets | ||
| const watchTargets = [ |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
The three createFileSystemWatcher boolean arguments are now unlabeled despite changing the change-event behavior. Please retain inline parameter-name comments so the create/change/delete semantics remain auditable.
Eleanor Boyd (eleanorjboyd)
left a comment
There was a problem hiding this comment.
Re-review at cbd90966: the existing terminal-only environment finding remains unresolved. I found two additional watcher lifecycle issues inline. Also, docs/startup-flow.md still says activation registers the deleted terminal package watcher and should be updated to describe registerPackageWatchers. Targeted TypeScript compilation, webpack compilation, and all 14 Package Watcher unit tests pass, but none cover these integration seams.
|
As per team-sync, we decided the best approach would be to replace the TerminalPackageWatcher with the PackageWatcher which was a more reliable and efficient way of detecting actual changes to the packages |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a7de2667-ab70-47de-a8fd-5b00953e14f7
| sharedWatchers.set(watcherKey, { | ||
| disposable: watchPackageChangesForEnvironment(environment, selectedPackageManager, log), | ||
| references: 1, | ||
| }); |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
The scoped-environment cache is only rebound here; it is never cleared when a project is removed. Ensure the authoritative project/environment lifecycle releases that scope, and add a regression test confirming the final watcher reference is disposed.
| const watcherKey = `${environment.envId.managerId}:${environment.envId.id}:${selectedPackageManager.id}`; | ||
| if (activeWatcherByConsumer.get(consumer) === watcherKey) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
A delayed activated: true event can arrive after onDidCloseTerminal releases this terminal, recreating a watcher with no later close event. Reject activation for closed terminals or track closed terminals, and test the close-before-activation ordering.
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a7de2667-ab70-47de-a8fd-5b00953e14f7
668c2af
| }; | ||
|
|
||
| const envChangeDisposable = envManager.onDidChangeEnvironment?.((changes) => { | ||
| const environmentChangeDisposable = envManagers.onDidChangeActiveEnvironment((changes) => { |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
Active consumers are not re-evaluated when onDidChangePackageManager reports registration or unregistration, so a late manager can leave an environment unwatched and removal can retain a stale watcher. Retain recomputation context for every consumer, subscribe to that lifecycle event, and add a test that registers and unregisters a manager after activation.
|
🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR. |
This pull request refactors and improves the package change detection and watcher system for Python environments. It consolidates the logic for watching package changes across all environment managers into a single, manager-agnostic watcher registration, and removes redundant or manager-specific watcher code. The new system ensures that package changes are detected and handled consistently, regardless of environment type or package manager.
Fixes #1683
Core improvements to package watcher system:
registerPackageWatchersfunction is introduced inpackageWatcher.ts, which registers package watchers for all active environments, sharing watchers when environments are active in multiple scopes and cleaning up watchers when no longer needed. This replaces the old per-manager watcher registration. (src/managers/common/packageWatcher.tsL2-R11, F89a1842L51R51).dist-infodirectories, catching more package changes. (F89a1842L18R18, F89a1842L43R43)Cleanup and removal of legacy code:
terminalPackageWatcher.tsand its related imports and registration are removed, as its functionality is now covered by the new watcher system. [1] [2] [3]builtin/main.tsandpoetry/main.ts, further consolidating watcher logic. [1] [2] [3] [4]API and test updates:
InternalPackageManagerclass now exposes agetPackageWatchTargetsmethod to allow custom watch targets per package manager.These changes improve maintainability, reliability, and coverage of package change detection across all Python environments managed by the extension.