Skip to content

Commit 3d68ec7

Browse files
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
1 parent e670c97 commit 3d68ec7

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

autoload/ale/cursor.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function! ale#cursor#TruncatedEcho(original_message) abort
2323
" Change tabs to spaces.
2424
let l:message = substitute(l:message, "\t", ' ', 'g')
2525
" Remove any newlines in the message.
26-
let l:message = substitute(l:message, "\n", '', 'g')
26+
let l:message = substitute(l:message, "\n", ' ', 'g')
2727
" Convert indentation groups into single spaces for better legibility when
2828
" put on a single line
2929
let l:message = substitute(l:message, ' \+', ' ', 'g')
@@ -93,6 +93,7 @@ function! ale#cursor#EchoCursorWarning(...) abort
9393
if !empty(l:loc)
9494
let l:format = ale#Var(l:buffer, 'echo_msg_format')
9595
let l:msg = ale#GetLocItemMessage(l:loc, l:format)
96+
9697
call ale#cursor#TruncatedEcho(l:msg)
9798
let l:info.echoed = 1
9899
elseif get(l:info, 'echoed')

autoload/ale/lsp/response.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function! ale#lsp#response#ReadDiagnostics(diagnostics) abort
2828
for l:diagnostic in a:diagnostics
2929
let l:severity = get(l:diagnostic, 'severity', 0)
3030
let l:loclist_item = {
31-
\ 'text': substitute(l:diagnostic.message, '\(\r\n\|\n\|\r\)', ' ', 'g'),
31+
\ 'text': l:diagnostic.message,
3232
\ 'type': 'E',
3333
\ 'lnum': l:diagnostic.range.start.line + 1,
3434
\ 'col': l:diagnostic.range.start.character + 1,

test/lsp/test_read_lsp_diagnostics.vader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ Execute(ale#lsp#response#ReadDiagnostics() should include sources in detail):
109109
\ }
110110
\ ])
111111

112-
Execute(ale#lsp#response#ReadDiagnostics() should keep detail with line breaks but replace with spaces in text):
112+
Execute(ale#lsp#response#ReadDiagnostics() should keep line breaks in text):
113113
AssertEqual [
114114
\ {
115115
\ 'type': 'E',
116-
\ 'text': 'cannot borrow `cap` as mutable more than once at a time mutable borrow starts here in previous iteration of loop',
116+
\ 'text': "cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop",
117117
\ 'detail': "[rustc] cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop",
118118
\ 'lnum': 10,
119119
\ 'col': 15,

test/test_cursor_warnings.vader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Before:
3030
\ 'nr': -1,
3131
\ 'type': 'E',
3232
\ 'code': 'semi',
33-
\ 'text': "Missing semicolon.\r",
33+
\ 'text': "Missing\nsemicolon.\r",
3434
\ 'detail': "Every statement should end with a semicolon\nsecond line",
3535
\ },
3636
\ {

0 commit comments

Comments
 (0)