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

Add middleware to intercept textDocument/publishDiagnostics #322

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

rcjsuen
Copy link
Contributor

@rcjsuen rcjsuen commented Mar 18, 2018

It is currently not possible for a client to inspect the contents of the textDocument/publishDiagnostics notifications from the server before letting VS Code handle them. This pull request introduces a middleware function to allow clients to intercept the contents of the notification before passing them off to VS Code.

@dbaeumer
Copy link
Member

dbaeumer commented Apr 5, 2018

@rcjsuen thanks for the PR. There is one thing I am not sure of how we should do it: the middleware API currently uses VS Code API types only. With this PR it will surface LSP types. Although this allows to intercept the notification as early as possible I would nevertheless change the types to VS Code API types. In the implementation that means we first convert the LSP data into VS Code data and then call the middleware.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Apr 5, 2018
@rcjsuen
Copy link
Contributor Author

rcjsuen commented Apr 5, 2018

@dbaeumer Hi Dirk, thanks for the review.

Should I still use NextSignature then? VS Code's Diagnostic does not contain information URI information so I am forced to change...

publishDiagnostics?: NextSignature<PublishDiagnosticsParams, void>;

...to...

publishDiagnostics?: NextSignature<Uri, VDiagnostic[], void>;

But this won't compile because NextSignature only takes two parameters.

Or should I instead write a new function like the following and just introduce a new HandleDiagnosticsSignature interface type?

handleDiagnostics?: (this: void, uri: Uri, diagnostic: VDiagnostics[], next: HandleDiagnosticsSignature) => void;

Clients may want to inspect diagnostics received from the server
before letting VS Code handle and display them. It is not possible to
use onNotification because the existing handler will be replaced.
Thus, we need to introduce a new middleware for the language client
to route the server's textDocument/publishDiagnostics notification
to. This will allow the client can do what it needs to do before then
forwarding it off to VS Code.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
@dbaeumer
Copy link
Member

dbaeumer commented Apr 6, 2018

@rcjsuen I would go with the HandleDiagnosticsSignature approach.

@rcjsuen
Copy link
Contributor Author

rcjsuen commented Apr 6, 2018

@dbaeumer Thank you. I've force pushed a new change to my branch. Feel free to take a look whenever you have the time. I'm sure you're a busy man.

@dbaeumer
Copy link
Member

dbaeumer commented Apr 6, 2018

Thanks for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants