From 3d68ec78572059b1bdb5f2f3fb85942e8627e118 Mon Sep 17 00:00:00 2001 From: Benjamin Block Date: Sun, 20 Jul 2025 06:47:26 -0400 Subject: [PATCH] Only strip newlines for echo, otherwise full messages (#4964) * Updates `ale#lsp#response#ReadDiagnostics` to always store the full, unaltered diagnostic message from the LSP in question. The current process is to replace all newline characters with whitespace (' '), which then leads to broken formatting when viewing complex output from an LSP with `:ALEDetail` and other commands. * Updates `ale#cursor#TruncatedEcho` to replace newline characters with a space ' ' instead of an empty string '' to retain the previous style of formatting for echoed messages. Fixes: #2356 Fixes: #3068 Fixes: #2301 --- autoload/ale/cursor.vim | 3 ++- autoload/ale/lsp/response.vim | 2 +- test/lsp/test_read_lsp_diagnostics.vader | 4 ++-- test/test_cursor_warnings.vader | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index da3b6922..86defdce 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -23,7 +23,7 @@ function! ale#cursor#TruncatedEcho(original_message) abort " Change tabs to spaces. let l:message = substitute(l:message, "\t", ' ', 'g') " Remove any newlines in the message. - let l:message = substitute(l:message, "\n", '', 'g') + let l:message = substitute(l:message, "\n", ' ', 'g') " Convert indentation groups into single spaces for better legibility when " put on a single line let l:message = substitute(l:message, ' \+', ' ', 'g') @@ -93,6 +93,7 @@ function! ale#cursor#EchoCursorWarning(...) abort if !empty(l:loc) let l:format = ale#Var(l:buffer, 'echo_msg_format') let l:msg = ale#GetLocItemMessage(l:loc, l:format) + call ale#cursor#TruncatedEcho(l:msg) let l:info.echoed = 1 elseif get(l:info, 'echoed') diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim index 85ac9e69..d2004b63 100644 --- a/autoload/ale/lsp/response.vim +++ b/autoload/ale/lsp/response.vim @@ -28,7 +28,7 @@ function! ale#lsp#response#ReadDiagnostics(diagnostics) abort for l:diagnostic in a:diagnostics let l:severity = get(l:diagnostic, 'severity', 0) let l:loclist_item = { - \ 'text': substitute(l:diagnostic.message, '\(\r\n\|\n\|\r\)', ' ', 'g'), + \ 'text': l:diagnostic.message, \ 'type': 'E', \ 'lnum': l:diagnostic.range.start.line + 1, \ 'col': l:diagnostic.range.start.character + 1, diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index 80f2e4f0..aa2d66c8 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -109,11 +109,11 @@ Execute(ale#lsp#response#ReadDiagnostics() should include sources in detail): \ } \ ]) -Execute(ale#lsp#response#ReadDiagnostics() should keep detail with line breaks but replace with spaces in text): +Execute(ale#lsp#response#ReadDiagnostics() should keep line breaks in text): AssertEqual [ \ { \ 'type': 'E', - \ 'text': 'cannot borrow `cap` as mutable more than once at a time mutable borrow starts here in previous iteration of loop', + \ 'text': "cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop", \ 'detail': "[rustc] cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop", \ 'lnum': 10, \ 'col': 15, diff --git a/test/test_cursor_warnings.vader b/test/test_cursor_warnings.vader index 99108c4a..3640ebe6 100644 --- a/test/test_cursor_warnings.vader +++ b/test/test_cursor_warnings.vader @@ -30,7 +30,7 @@ Before: \ 'nr': -1, \ 'type': 'E', \ 'code': 'semi', - \ 'text': "Missing semicolon.\r", + \ 'text': "Missing\nsemicolon.\r", \ 'detail': "Every statement should end with a semicolon\nsecond line", \ }, \ {