Skip to content

Multiple onNotification/onRequest registration - #65

Merged
dhuebner merged 1 commit into
mainfrom
dhuebner/handler-registration-63
Aug 31, 2026
Merged

dhuebner merged 1 commit into
mainfrom
dhuebner/handler-registration-63

Conversation

@dhuebner

@dhuebner dhuebner commented Aug 28, 2026

Copy link
Copy Markdown
Member

Fixes #63

Registering overlapping onRequest/onNotification handlers previously failed silently
(webview side: last registration wins, dispose() could remove the wrong handler) or only
surfaced as a runtime dispatch error (host side: "Multiple matching request handlers").

This PR enforces handler invariants at registration time on both sides:

  • Kind homogeneity: a method must be used exclusively for requests or notifications;
    registering the opposite kind throws immediately.
  • Request uniqueness per scope: a second onRequest for the same method throws if its
    sender scope overlaps an existing one (host side); the webview side allows at most one
    request handler per method.
  • Notification stacking: onNotification still stacks freely - all matching handlers fire.
  • Disposable.dispose() removes by identity, not by method name, so stacked notification
    handlers can be managed independently.

See ADR-0004 for the full design rationale
and breaking-change notes (shipped as a minor version bump under 0.x SemVer, v0.7.0).

Also includes: ADRs 0001-0003 documenting prior design decisions, updated ARCHITECTURE.md,
new vscode-messenger-common/src/util.ts for shared participant/error-message helpers, and
expanded test coverage for the new registration-enforcement behavior on both host and webview
sides.

@dhuebner dhuebner changed the title Multiple onNotification/onRequest registration #63 Multiple onNotification/onRequest registration Aug 28, 2026
- Enhanced `ARCHITECTURE.md` to include new types and internal utilities.
- Added ADRs for two-sided cancellation bridge, webview participant union type, disposable return from handler registration, and handler registration enforcement.
- Introduced `util.ts` for shared internal utilities.
- Updated package versions to 0.7.0 across all relevant packages.
- Implemented breaking changes in handler registration to enforce unique request and notification handlers.
- Updated tests to reflect new handler registration behavior and ensure proper error handling.
@dhuebner
dhuebner force-pushed the dhuebner/handler-registration-63 branch from 0022b01 to 557008e Compare August 28, 2026 11:20

@jonah-iden jonah-iden 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.

Looks pretty good to me.
I guess registering a handler first for notification and request can only happen if you don't define your message types correctly beforehand right? Otherwise it would already be catched at compile time. But still good to have that extra security.
documentation also looks pretty good to me

@dhuebner
dhuebner merged commit f5cefee into main Aug 31, 2026
1 check passed
@dhuebner
dhuebner deleted the dhuebner/handler-registration-63 branch September 4, 2026 10:41
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.

Multiple onNotification/onRequest registration

2 participants