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
x/tools/gopls: hoverKind FullDocumentation is incorrectly escaping various characters #38656
Comments
Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here. |
Actually I think the |
^ Nevermind, I confirm gopls is indeed returning escaped &, that's why I see |
This is probably because lsp-mode is requesting its hover results to be formatted in Markdown. There is an option on the language client's end to request plaintext results, but a lot of clients choose Markdown because users may have other plugins installed that display Markdown nicely. I would recommend opening up an issue to offer a configuration in lsp-mode or seeing if you can install a plugin to format the hover. |
I see this is expected based on the LSP spec. So I'll dig further on the lsp-mode side. |
lsp-mode change to handle this at emacs-lsp/lsp-mode#1614. @stamblerre do you know why gopls returns so much whitespace around indents though? For example here is the original godoc:
And the MarkupContent inserts 2 lines between the sentence and the following indent: "contents": {
"value": "```go\nfunc ..Expect(actual interface{}, extra ...interface{}) ..Assertion\n```\n\n[`gomega.Expect` on pkg.go.dev](https://pkg.go.dev/github.com/onsi/gomega@v1.5.0#Expect)\n\nExpect wraps an actual value allowing assertions to be made on it\\:\n\n\n Expect(\"foo\").To(Equal(\"foo\"))\n\n\nIf Expect is passed more than one argument it will pass the \\*first\\* argument to the matcher\\.\nAll subsequent arguments will be required to be nil\\/zero\\.\n\nThis is convenient if you want to make an assertion on a method\\/function that returns\na value and an error \\- a common patter in Go\\.\n\nFor example, given a function with signature\\:\n\n\n func MyAmazingThing() (int, error)\n\n\nThen\\:\n\n\n Expect(MyAmazingThing()).Should(Equal(3))\n\n\nWill succeed only if \\`MyAmazingThing\\(\\)\\` returns \\`\\(3, nil\\)\\`\n\nExpect and Ω are identical\n",
"kind": "markdown"
} |
I believe that this is done to make the indent render properly in the Markdown. I'm not an expert, but this is the code that does the conversion: https://github.com/golang/tools/blob/f3a5411a4c3bfd7b6429abf664039dc43b37d985/internal/lsp/source/comment.go#L40. I would imagine that the extra whitespace will not be there in the plaintext mode. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have set
"hoverKind": "FullDocumentation"
as added in #32561. This works, but it inserts a lot of escaped characters into the markdown description that it doesn't need to. I'm not quite sure why.Here is an example for
fmt#Errorf
:Rendering this via markdown (inside Emacs via lsp-mode) produces this:
I'm also seeing html entities being escaped:
In the raw JSON this looks like
\u0026nbsp;
.What did you expect to see?
Full documentation without any escape characters.
What did you see instead?
Full documentation with lots of embedded escape characters.
The text was updated successfully, but these errors were encountered: