Repository navigation
Dispose plugin registrations through scopes - #67
Merged
Merged
Conversation
A plugin's `onEnable` and `onTerminalOpen` receive a scope, and every `add*` method takes one and returns nothing. The host disposes the scope when the plugin is disabled, when its `onEnable` throws, or when the terminal closes, so a failed enable no longer leaves registrations behind. `onDisable` and the disposables `onEnable` returned are removed; `scope.add` covers both. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
They failed since the default branch prefix was added: one still expected an empty branch, and the dialog suspended on the settings, which the projects test harness never loaded, so focus was lost before the dialog opened. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
onEnable(scope, app)andonTerminalOpen(scope, app, view)receive aScope, always as the first parameter. The host disposes it when the plugin is disabled, whenonEnablethrows, or when the terminal closes.add*method takes a scope and returns nothing. The 23 methods of the frontend contract are nowadd(scope, items): void. An item is removed when its scope is disposed, and nothing is added to a scope that is already disposed.onEnableno longer leaks. Whatever the plugin added before the throw is disposed with its scope. Before, the registrations made before the throw stayed.onDisableandonEnable's returned disposables are removed.scope.add(disposable)covers a plugin's own resources.scope.child()gives early removal. A child is disposed with its parent, or earlier through its owndispose().ScopeandCustomScopeare interfaces in@elsewise/plugin, implemented byPluginScopein@elsewise/core.APPLICATION_SCOPEis the application's own scope, never disposed, which the built-ins and the tests pass.Notes
dispose()starts on a microtask.onTerminalCloseis called before the terminal's scope is disposed.TerminalManager.addAddonstracks each addition, so a factory added under two scopes stays until both are disposed. Before, disposing the first removed the addon from every terminal.MenuManagerandSortedSetstill return a disposable; the managers over them take the scope.onPanelOpenandonWorkspaceChangeget no scope yet. Panel opens and closes are not reported across workspace switches, and a workspace change is too broad an event to bind a lifetime to.onTerminalOpenis not called for terminals that are already open when a plugin is enabled, as before.dispose()on the scopeonEnablereceives, since only theScopetype hides it.Testing
core: check, typecheck and tests (111 passed) pass. Newscope.test.tscovers order, async and throwing disposables, children and the application scope.daemon: check, typecheck, tests (503 passed), build and bundle tests (6 passed) pass on macOS arm64.web: check, typecheck, Node tests (454 passed) and visual tests (262 passed, no baseline changed) pass.webbrowser tests: 1570 passed, 1 skipped. Two tests innew-workspace-dialog.browser.test.tsxthat have failed onmainsince Fix symlinked file updates and comparison scroll, add a default branch prefix #63 are fixed here: one expected an empty branch where the default prefix now applies, and the projects test harness never loaded the settings, so the dialog suspended and focus was lost before it opened. CI does not run the browser tests.🤖 Generated with Claude Code