Skip to content

Commit 8237501

Browse files
Truncate diagnostics cursor message when message is too long (#191)
* truncate diagnostics message * fix echo with truncation
1 parent 40825e3 commit 8237501

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

autoload/lsp/ui/vim/diagnostics/echo.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endfunction
2222
function! s:echo_diagnostics_under_cursor(...) abort
2323
let l:diagnostic = lsp#ui#vim#diagnostics#get_diagnostics_under_cursor()
2424
if !empty(l:diagnostic) && has_key(l:diagnostic, 'message')
25-
echo 'LSP: '. substitute(l:diagnostic['message'], '\n\+', ' ', 'g')
25+
call lsp#utils#echo_with_truncation('LSP: '. substitute(l:diagnostic['message'], '\n\+', ' ', 'g'))
2626
endif
2727
endfunction
2828

autoload/lsp/utils.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,14 @@ function! lsp#utils#error(msg) abort
138138
echom a:msg
139139
echohl NONE
140140
endfunction
141+
142+
function! lsp#utils#echo_with_truncation(msg) abort
143+
let l:msg = a:msg
144+
let l:winwidth = winwidth(0)
145+
146+
if l:winwidth < strdisplaywidth(l:msg)
147+
let l:msg = l:msg[:l:winwidth - 5] . '...'
148+
endif
149+
150+
exec 'echo l:msg'
151+
endfunction

0 commit comments

Comments
 (0)