emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.81k stars 890 forks source link

lsp-describe-thing-at-point should trim whitespace from all lines #4572

Closed wavexx closed 1 month ago

wavexx commented 1 month ago

Thank you for the bug report

Bug description

Using lsp-mode with clangd, and pointing anything at `lsp-describe-thing-at-point' I see trailing whitespace in the resulting buffer. I notice because some of the faces being used use underline which extends past the end of the line.

Looking at the definition of `lsp-describe-thing-at-point' we see the actual buffer is inserted with:

(insert (string-trim-right (lsp--render-on-hover-content contents t)))))

which strips whitespace out of the last line only. Changing this to use split/trim/mapconcat works as expected, but I'm unsure looking at the code if the whitespace shouldn't be stripped by lsp--render-on-hover-content directly. If not, I would provide a PR.

Steps to reproduce

Try to open/describe any C variable by using `lsp-describe-thing-at-point' with clangd. A plain C file with:

float PI = 3.1415926f;

shows:

2024-10-02T151851

Expected behavior

The description shouldn't contain trailing whitespace.

Which Language Server did you use?

lsp-clangd

OS

Linux

Error callstack

No response

Anything else?

No response