diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index e8478e93..ac6b48ba 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -16,6 +16,9 @@ function! ale#cursor#TruncatedEcho(original_message) abort let l:message = substitute(l:message, "\t", ' ', 'g') " Remove any newlines in the message. 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') " We need to remember the setting for shortmess and reset it again. let l:shortmess_options = &l:shortmess @@ -27,7 +30,14 @@ function! ale#cursor#TruncatedEcho(original_message) abort silent! setlocal shortmess+=T try - exec "norm! :echomsg l:message\n" + " echon will not display the message if it exceeds the width of + " the window + if &columns < strdisplaywidth(l:message) + " Truncate message longer than window width with trailing '...' + let l:message = l:message[:&columns - 5] . '...' + endif + + echon l:message catch /^Vim\%((\a\+)\)\=:E523/ " Fallback into manual truncate (#1987) let l:winwidth = winwidth(0) diff --git a/autoload/ale/hover.vim b/autoload/ale/hover.vim index 4513c6ad..a738c848 100644 --- a/autoload/ale/hover.vim +++ b/autoload/ale/hover.vim @@ -46,7 +46,7 @@ function! ale#hover#HandleTSServerResponse(conn_id, response) abort call balloon_show(a:response.body.displayString) elseif get(l:options, 'truncated_echo', 0) if !empty(a:response.body.displayString) - call ale#cursor#TruncatedEcho(split(a:response.body.displayString, "\n")[0]) + call ale#cursor#TruncatedEcho(a:response.body.displayString) endif elseif g:ale_hover_to_floating_preview || g:ale_floating_preview call ale#floating_preview#Show(split(a:response.body.displayString, "\n"), { @@ -231,7 +231,7 @@ function! ale#hover#HandleLSPResponse(conn_id, response) abort \&& (l:set_balloons is 1 || l:set_balloons is# 'hover') call balloon_show(join(l:lines, "\n")) elseif get(l:options, 'truncated_echo', 0) - call ale#cursor#TruncatedEcho(l:lines[0]) + call ale#cursor#TruncatedEcho(join(l:lines[0], '\n')) elseif g:ale_hover_to_floating_preview || g:ale_floating_preview call ale#floating_preview#Show(l:lines, { \ 'filetype': 'ale-preview.message', diff --git a/test/script/custom-linting-rules b/test/script/custom-linting-rules index 12dec4c1..d3f5e3f3 100755 --- a/test/script/custom-linting-rules +++ b/test/script/custom-linting-rules @@ -125,7 +125,7 @@ check_errors '==#' "Use 'is#' instead of '==#'. 0 ==# 'foobar' is true" check_errors '==?' "Use 'is?' instead of '==?'. 0 ==? 'foobar' is true" check_errors '!=#' "Use 'isnot#' instead of '!=#'. 0 !=# 'foobar' is false" check_errors '!=?' "Use 'isnot?' instead of '!=?'. 0 !=? 'foobar' is false" -check_errors '^ *:\?echo' "Stray echo line. Use \`execute echo\` if you want to echo something" +check_errors '^ *:\?echo\>' "Stray echo line. Use \`execute echo\` if you want to echo something" check_errors '^ *:\?redir' 'User execute() instead of redir' # Exclusions for grandfathered-in exceptions exclusions="clojure/clj_kondo.vim elixir/elixir_ls.vim go/golangci_lint.vim swift/swiftformat.vim"