Allow plugins to modify server response messages #1992
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This method for
AbstractPlugin
allows LSP-* plugins to modify the "result" in (successful) response messages from the server, before it gets further processed by the response handler function in LSP.It is useful especially for problematic content in hover responses, but the implementation is generic enough to allow plugins to do any shenanigans they like with the payload ;)
Examples:
Hover popups from LSP-pyright have some minor issues (sublimelsp/LSP-pyright#42), for example there is occasionally only a single
\n
between the end of a fenced code block and---
(horizontal rule). This is absolutely fine in CommonMark, but mdpopups (or the Python-Markdown parser or whatever it uses) mistakenly interprets it as a Setext header, i.e. currently the code will be bold and the horizontal rule is omitted:Add the following lines to LSP-pyright in
plugin.py
, and it will be displayed correctly:I would like to use it for the hover popups from the Julia language server, which have several similar issues in their Markdown content. In particular they often use links formatted in the form
[`title`](@ref)
, and as soon as you click on the link, it will start a webbroser and try to open@ref
as URL, which of course doesn't work. But with small modifications I could make these links to open a corresponding documentation page from the server in a HtmlSheet - https://github.com/sublimelsp/LSP-julia/blob/50f978826407faf0d1aaebcd3c2f8e5cb53f8136/plugin.py#L543-L562