Skip to content

Support multiple handlers of JSON-RPC Notifications #533

@mhintzke

Description

@mhintzke

I am trying to build an application that utilizes monaco editor to support writing PowerShell in the browser. We have a requirement to disallow saving of a file when there are script diagnostic errors present. This means I need my application to know when the Diagnostics change which sent me down a path to use the IConnection.onDiagnostics(...) method to handle when the diagnostics are updated.

However, when I did this in my application code, all of a sudden the monaco editor stopped displaying the errors and warnings in the editor itself. So I dove into the code and found this:

notificationHandlers[type.method] = { type, handler };

This line of code is overwriting the handler when a new handler is set, effectively only allowing a single handler to be used for a given notification type. So clearly, when I try to handle diagnostic updates in my application code I am removing the handler that is set here:

connection.onDiagnostics(params => this.handleDiagnostics(params));

Is there something in the JSON-RPC spec that disallows multiple handlers to be used? This seems like something very simple to introduce if it is allowed by the spec. Is there some other way I could be handling this that is already supported? I guess I'm surprised that no one else has needed this kind of functionality before.

Without this change, I will have to introduce much more code to "poll" for the diagnostics during each Angular change detection cycle which is definitely less elegant or performant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions