Skip to content

Commit 79d47fe

Browse files
Fix g:lsp_preview_max_width for Neovim (#440)
* Fix g:lsp_preview_max_width for Neovim * Fix max_width also specifying minimum width
1 parent c2b7c23 commit 79d47fe

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

autoload/lsp/ui/vim/output.vim

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ function! s:setcontent(lines, ft) abort
149149
" nvim floating or preview
150150
call setline(1, a:lines)
151151

152-
" Set maximum width of floating window, if specified
153-
if g:lsp_preview_max_width > 0
154-
let &l:textwidth = g:lsp_preview_max_width
155-
normal! gggqGgg
156-
endif
157-
158152
setlocal readonly nomodifiable
159153
try
160154
let &l:filetype = a:ft . '.lsp-hover'
@@ -307,8 +301,20 @@ function! lsp#ui#vim#output#preview(data, options) abort
307301
call s:setcontent(l:lines, l:ft)
308302

309303
" Get size information while still having the buffer active
310-
let l:bufferlines = line('$')
311304
let l:maxwidth = max(map(getline(1, '$'), 'strdisplaywidth(v:val)'))
305+
if g:lsp_preview_max_width > 0
306+
let l:bufferlines = 0
307+
let l:maxwidth = min([g:lsp_preview_max_width, l:maxwidth])
308+
309+
" Determine, for each line, how many "virtual" lines it spans, and add
310+
" these together for all lines in the buffer
311+
for l:line in getline(1, '$')
312+
let l:num_lines = str2nr(string(ceil(strdisplaywidth(l:line) * 1.0 / g:lsp_preview_max_width)))
313+
let l:bufferlines += max([l:num_lines, 1])
314+
endfor
315+
else
316+
let l:bufferlines = line('$')
317+
endif
312318

313319
if s:use_preview
314320
" Set statusline

0 commit comments

Comments
 (0)