Skip to content

Dispose plugin registrations through scopes - #67

Merged
Pante merged 2 commits into
mainfrom
feature/better-plugin-disposables
Dec 1, 2026
Merged

Pante merged 2 commits into
mainfrom
feature/better-plugin-disposables

Conversation

@Pante

@Pante Pante commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Plugins get a scope. onEnable(scope, app) and onTerminalOpen(scope, app, view) receive a Scope, always as the first parameter. The host disposes it when the plugin is disabled, when onEnable throws, or when the terminal closes.
  • Every add* method takes a scope and returns nothing. The 23 methods of the frontend contract are now add(scope, items): void. An item is removed when its scope is disposed, and nothing is added to a scope that is already disposed.
  • A failed onEnable no longer leaks. Whatever the plugin added before the throw is disposed with its scope. Before, the registrations made before the throw stayed.
  • onDisable and onEnable'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 own dispose().
  • Scope and CustomScope are interfaces in @elsewise/plugin, implemented by PluginScope in @elsewise/core. APPLICATION_SCOPE is the application's own scope, never disposed, which the built-ins and the tests pass.

Notes

  • Disposal is in reverse order of adding and waits for each disposable, with the 15 second limit applied to each one.
  • Removal is no longer synchronous: dispose() starts on a microtask.
  • The host's hook listeners live in a scope of their own that is disposed before the plugin's, so no hook reaches a plugin that is being disposed.
  • onTerminalClose is called before the terminal's scope is disposed.
  • TerminalManager.addAddons tracks each addition, so a factory added under two scopes stays until both are disposed. Before, disposing the first removed the addon from every terminal.
  • MenuManager and SortedSet still return a disposable; the managers over them take the scope.
  • onPanelOpen and onWorkspaceChange get 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.
  • onTerminalOpen is not called for terminals that are already open when a plugin is enabled, as before.
  • A plugin written in JavaScript can still call dispose() on the scope onEnable receives, since only the Scope type hides it.

Testing

  • core: check, typecheck and tests (111 passed) pass. New scope.test.ts covers 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.
  • web browser tests: 1570 passed, 1 skipped. Two tests in new-workspace-dialog.browser.test.tsx that have failed on main since 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.
  • The example plugins and the starter typecheck.
  • Not run: the desktop app, Linux and Windows.

🤖 Generated with Claude Code

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>
@claude

claude Bot commented Nov 30, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Pante
Pante requested a review from kawaijoe November 30, 2026 14:14
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>

@kawaijoe kawaijoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Pante
Pante added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 69cb9f2 Dec 1, 2026
21 checks passed
@Pante
Pante deleted the feature/better-plugin-disposables branch December 1, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants