Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion autoload/lsp/internal/completion/documentation.vim
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,25 @@ function! s:show_floating_window(event, managed_user_data) abort
return
endif

" Preserve scroll position when the window already exists.
let l:topline = 1
if l:doc_win.is_visible()
let l:winid = l:doc_win.get_winid()
if has('nvim')
let l:topline = line('w0', l:winid)
else
let l:topline = get(popup_getpos(l:winid), 'firstline', 1)
endif
endif

" Show popupmenu and apply markdown syntax.
call l:doc_win.open({
\ 'row': l:pos[0] + 1,
\ 'col': l:pos[1] + 1,
\ 'width': l:size.width,
\ 'height': l:size.height,
\ 'border': v:true,
\ 'topline': 1,
\ 'topline': l:topline,
\ })
call s:Window.do(l:doc_win.get_winid(), { -> s:Markdown.apply() })
endfunction
Expand Down Expand Up @@ -189,6 +200,7 @@ function! s:get_doc_win() abort
\ })
call s:doc_win.set_var('&wrap', 1)
call s:doc_win.set_var('&conceallevel', 2)
call s:doc_win.set_var('&concealcursor', 'nvic')
noautocmd silent let l:bufnr = s:Buffer.create()
call s:doc_win.set_bufnr(l:bufnr)
call setbufvar(s:doc_win.get_bufnr(), '&buftype', 'nofile')
Expand Down
18 changes: 18 additions & 0 deletions autoload/lsp/ui/vim/output.vim
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ function! lsp#ui#vim#output#preview(server, data, options) abort
return
endif

let l:prev_topline = 1
if s:winid
if s:use_vim_popup
let l:prev_topline = get(popup_getpos(s:winid), 'firstline', 1)
else
let l:prev_topline = line('w0', s:winid)
endif
endif

if s:winid && type(s:preview_data) ==# type(a:data)
\ && s:preview_data ==# a:data
\ && type(g:lsp_preview_doubletap) ==# 3
Expand Down Expand Up @@ -365,6 +374,8 @@ function! lsp#ui#vim#output#preview(server, data, options) abort

call setbufvar(winbufnr(s:winid), 'lsp_syntax_highlights', l:syntax_lines)
call setbufvar(winbufnr(s:winid), 'lsp_do_conceal', l:do_conceal)
call setwinvar(s:winid, '&conceallevel', l:do_conceal ? 2 : 0)
call setwinvar(s:winid, '&concealcursor', l:do_conceal ? 'nvic' : '')
call lsp#ui#vim#output#setcontent(s:winid, l:lines, l:ft)

let [l:bufferlines, l:maxwidth] = lsp#ui#vim#output#get_size_info(s:winid)
Expand Down Expand Up @@ -393,6 +404,13 @@ function! lsp#ui#vim#output#preview(server, data, options) abort
" Vim popups
call s:set_cursor(l:current_window_id, a:options)
endif
if l:prev_topline > 1
if s:use_vim_popup
call popup_setoptions(s:winid, {'firstline': l:prev_topline})
elseif s:use_nvim_float
call nvim_win_set_cursor(s:winid, [l:prev_topline, 0])
endif
endif
doautocmd <nomodeline> User lsp_float_opened
endif

Expand Down