Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple handlers of JSON-RPC Notifications #533

Closed
mhintzke opened this issue Oct 23, 2019 · 4 comments
Closed

Support multiple handlers of JSON-RPC Notifications #533

mhintzke opened this issue Oct 23, 2019 · 4 comments

Comments

@mhintzke
Copy link

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.

@mhintzke
Copy link
Author

mhintzke commented Oct 23, 2019

After trying to figure out how to do this in an alternative fashion, I realized that in a newer version of the vscode-languageclient there is a middleware options you can add to the LanguageServiceOptions which allows you to hook into the handler of Diagnostics:

#322

The above PR outlines the exact issue I am facing. I will attempt to update to a newer version which should allow me to get this functionality. Previously we were unable to upgarde the package due to other depenedencies have conflicts, but looks like we will have to figure it out.

I would still like to address the larger concern of Notification in general not allowing multiple handlers and would like to understand why we cannot support that natively with JSON RPC

@rcjsuen
Copy link
Contributor

rcjsuen commented Oct 23, 2019

This request sounds similar to #174.

@mhintzke
Copy link
Author

Thanks, this is similar to the issue, but not identical. I did comment over there to try to resurrect the issue as its been over 2 years and no signs of fixes have been found.

I'm not against fixing it myself, I just wanted to know if there was some good reason for not supporting this behavior.

@dbaeumer
Copy link
Member

Closing in favour of #174

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants