@@ -11,24 +11,43 @@ function! lsp#ui#vim#output#closepreview() abort
11
11
autocmd ! lsp_float_preview_close CursorMoved ,CursorMovedI ,VimResized *
12
12
endfunction
13
13
14
+ function ! s: bufwidth ()
15
+ let width = winwidth (0 )
16
+ let numberwidth = max ([&numberwidth , strlen (line (' $' ))+ 1 ])
17
+ let numwidth = (&number || &relativenumber )? numberwidth : 0
18
+ let foldwidth = &foldcolumn
19
+
20
+ if &signcolumn == ' yes'
21
+ let signwidth = 2
22
+ elseif &signcolumn == ' auto'
23
+ let signs = execute (printf (' sign place buffer=%d' , bufnr (' ' )))
24
+ let signs = split (signs, " \n " )
25
+ let signwidth = len (signs)>2 ? 2 : 0
26
+ else
27
+ let signwidth = 0
28
+ endif
29
+ return width - numwidth - foldwidth - signwidth
30
+ endfunction
31
+
32
+
14
33
function ! s: get_float_positioning (height, width) abort
15
34
let l: height = a: height
16
35
let l: width = a: width
17
36
" For a start show it below/above the cursor
18
37
" TODO: add option to configure it 'docked' at the bottom/top/right
19
38
let l: y = winline ()
20
- if l: y + l: height >= & lines
39
+ if l: y + l: height >= winheight ( 0 )
21
40
" Float does not fit
22
41
if l: y - 2 > l: height
23
42
" Fits above
24
43
let l: y = winline () - l: height
25
- elseif l: y - 2 > & lines - l: y
44
+ elseif l: y - 2 > winheight ( 0 ) - l: y
26
45
" Take space above cursor
27
46
let l: y = 1
28
47
let l: height = winline ()-2
29
48
else
30
49
" Take space below cursor
31
- let l: height = & lines - l: y
50
+ let l: height = winheight ( 0 ) - l: y
32
51
endif
33
52
endif
34
53
let l: col = col (' .' )
@@ -48,7 +67,7 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
48
67
call setbufvar (l: buf , ' &signcolumn' , ' no' )
49
68
50
69
" Try to get as much pace right-bolow the cursor, but at least 10x10
51
- let l: width = max ([float2nr (& columns - col ( ' . ' ) - 10 ), 10 ])
70
+ let l: width = max ([s: bufwidth ( ), 10 ])
52
71
let l: height = max ([&lines - winline () + 1 , 10 ])
53
72
54
73
let l: opts = s: get_float_positioning (l: height , l: width )
0 commit comments