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

Invalid HTML in diagnostics["code"] breaks hover popups. #2223

Closed
ShrykeWindgrace opened this issue Mar 21, 2023 · 2 comments · Fixed by #2228
Closed

Invalid HTML in diagnostics["code"] breaks hover popups. #2223

ShrykeWindgrace opened this issue Mar 21, 2023 · 2 comments · Fixed by #2228

Comments

@ShrykeWindgrace
Copy link

Describe the bug
If the code field of the diagnostic contains invalid html, the hover popup is broken

To Reproduce
Steps to reproduce the behavior:

  1. Use haskell-language-server
  2. hover over a line with redundant <$> hint (for example, inputForConfig config = (<> config) <$> standardIOConfig >>= inputForConfig
  3. The hover popup is cut in half, and ST's console complaints about parsing errors

Expected behavior
Hover is properly formatted

Environment (please complete the following information):

  • OS: Win10
  • Sublime Text version: 4143
  • LSP version: current master
  • Language servers used: [HLS] with suggested config

Root cause
In the format_diagnostics_for_html method we append the contents of diagnostics["code"] as-is, without escaping (https://github.com/sublimelsp/LSP/blob/main/plugin/core/views.py#L1006).

As far as I understand, the specs of LSP say nothing about that field, it can be an arbitrary text. I suggest
the following diff:

diff --git a/plugin/core/views.py b/plugin/core/views.py
index cfdce3e..7af8239 100644
--- a/plugin/core/views.py
+++ b/plugin/core/views.py
@@ -1003,7 +1003,7 @@ def format_diagnostic_for_html(
         if code_description:
             code.append(make_link(code_description["href"], diagnostic.get("code")))
         else:
-            code.append(_with_color(diagnostic["code"], "color(var(--foreground) alpha(0.6))"))
+            code.append(_with_color(text2html(diagnostic["code"]), "color(var(--foreground) alpha(0.6))"))
         code.append(_with_color(")", "color(var(--foreground) alpha(0.6))"))
     else:
         code = None

I do not have a good idea on how it could impact other LSP servers, comments and suggestions are welcome.

I'll submit a PR sometime later this week.

Cheers!

@rchl
Copy link
Member

rchl commented Mar 24, 2023

Yes, text2html is the correct thing to use here. But there are quite a few more places that need it. Everywhere we get disagnostic code, source or the relatedInformation[0]['message]

@ShrykeWindgrace
Copy link
Author

@rchl thanks for the confirmation! However, I am not sufficiently familiar with codebase to add that text2html in all required places, the PR will take some time=)

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 a pull request may close this issue.

2 participants