Skip to content

Commit 4a5a0da

Browse files
committed
Fix hover float positioning
1 parent bb163c9 commit 4a5a0da

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

autoload/lsp/ui/vim/output.vim

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,43 @@ function! lsp#ui#vim#output#closepreview() abort
1111
autocmd! lsp_float_preview_close CursorMoved,CursorMovedI,VimResized *
1212
endfunction
1313

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+
1433
function! s:get_float_positioning(height, width) abort
1534
let l:height = a:height
1635
let l:width = a:width
1736
" For a start show it below/above the cursor
1837
" TODO: add option to configure it 'docked' at the bottom/top/right
1938
let l:y = winline()
20-
if l:y + l:height >= &lines
39+
if l:y + l:height >= winheight(0)
2140
" Float does not fit
2241
if l:y - 2 > l:height
2342
" Fits above
2443
let l:y = winline() - l:height
25-
elseif l:y - 2 > &lines - l:y
44+
elseif l:y - 2 > winheight(0) - l:y
2645
" Take space above cursor
2746
let l:y = 1
2847
let l:height = winline()-2
2948
else
3049
" Take space below cursor
31-
let l:height = &lines -l:y
50+
let l:height = winheight(0) -l:y
3251
endif
3352
endif
3453
let l:col = col('.')
@@ -48,7 +67,7 @@ function! lsp#ui#vim#output#floatingpreview(data) abort
4867
call setbufvar(l:buf, '&signcolumn', 'no')
4968

5069
" 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])
5271
let l:height = max([&lines - winline() + 1, 10])
5372

5473
let l:opts = s:get_float_positioning(l:height, l:width)

0 commit comments

Comments
 (0)