nvimdev / lspsaga.nvim

improve neovim lsp experience
MIT License
3.48k stars 287 forks source link

newlines are stripped from `show_line_diagnostics` content #1502

Open flrgh opened 2 hours ago

flrgh commented 2 hours ago

Describe the bug

Hi there :wave:

I've noticed that newlines are stripped from diagnostic messages from show_line_diagnostics, which can render them distorted/unreadable in some cases.

Steps to reproduce

min.lua ``` vim.opt.rtp:append('~/.local/share/nvim/lazy/lspsaga.nvim') vim.opt.rtp:append('~/.local/share/nvim/lazy/nvim-lspconfig') local lspconfig = require('lspconfig') -- setup rust-analyzer with default config lspconfig.rust_analyzer.setup({}) -- don't show inline diagnostics vim.diagnostic.enable(false) require('lspsaga').setup({}) ```
main.rs ``` fn demo(arg: String) { println!("{arg}"); } fn main() { let s = "my string".to_string(); demo(s); demo(s); } ```
nvim --clean -u min.lua main.rs

Expected behavior

Here's an example from rust-analyzer where the message contents are:

use of moved value: `s`\nvalue used here after move"

vim.diagnostic.open_float()

The builtin diagnostic float handler preserves the newline, as expected.

screenshot ![image](https://github.com/user-attachments/assets/0e38b46c-695c-45fa-ab3c-0d35525b4ed2)

Lspsaga show_line_diagnostics

Lspsaga strips the newline before rendering.

screenshot (minimal) ![image](https://github.com/user-attachments/assets/5326d96e-925e-4c89-a12b-fade05f6f3d0)

The minimum repro example is still somewhat readable, but in my full config where the ` is hidden by the markdown render process (not sure why--different problem I guess), things get even less readable:

screenshot (full) ![image](https://github.com/user-attachments/assets/c305553e-201e-4af1-ae96-92caf7089cb2)

Neovim version (nvim -v)

0.10.2

lspsaga commit

d027f8b9c7c55e26cf4030c8657a2fc8222ed762

Terminal name/version

alacritty 0.14.0

flrgh commented 2 hours ago

I'm sympathetic to the fact that the message we're receiving from rust-analyzer is not super great. The purpose of the newline in the message is kind of ambiguous, making it difficult for lspsaga to decide how to consume the message. If the newline is intended to be a line break that separates two distinct statements, it's probably "significant" and shouldn't be stripped, but if it's just text-wrapping that survives from the source material then a renderer/consumer should be able to treat it as superfluous and strip it away.