@@ -149,12 +149,6 @@ function! s:setcontent(lines, ft) abort
149
149
" nvim floating or preview
150
150
call setline (1 , a: lines )
151
151
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
-
158
152
setlocal readonly nomodifiable
159
153
try
160
154
let &l: filetype = a: ft . ' .lsp-hover'
@@ -307,8 +301,20 @@ function! lsp#ui#vim#output#preview(data, options) abort
307
301
call s: setcontent (l: lines , l: ft )
308
302
309
303
" Get size information while still having the buffer active
310
- let l: bufferlines = line (' $' )
311
304
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
312
318
313
319
if s: use_preview
314
320
" Set statusline
0 commit comments