Skip to content
Closed
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
61 changes: 32 additions & 29 deletions autoload/lsp/ui/vim/output.vim
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
function! lsp#ui#vim#output#preview(data) abort
" Close any previously opened preview window
pclose
if has('patch-8.1.1517')
let l:winid = popup_atcursor('...', {
\ 'moved': 'any',
\ 'border': [1, 1, 1, 1],
\})
let l:buf = winbufnr(l:winid)
let [l:ft, l:lines] = s:tolines(a:data)
call setbufline(l:buf, 1, split(l:lines, "\n"))
call win_execute(l:winid, 'setlocal filetype=' . l:ft . '.lsp-hover')
else
" Close any previously opened preview window
pclose

let l:current_window_id = win_getid()
let l:current_window_id = win_getid()

execute &previewheight.'new'
execute &previewheight.'new'

let l:ft = s:append(a:data)
" Delete first empty line
0delete _
let [l:ft, l:lines] = s:tolines(a:data)
call setline(1, split(l:lines, "\n"))

setlocal readonly nomodifiable
setlocal readonly nomodifiable

let &l:filetype = l:ft . '.lsp-hover'
let &l:filetype = l:ft . '.lsp-hover'

if g:lsp_preview_keep_focus
" restore focus to the previous window
call win_gotoid(l:current_window_id)
endif
if g:lsp_preview_keep_focus
" restore focus to the previous window
call win_gotoid(l:current_window_id)
endif

echo ''
echo ''
endif

return ''
endfunction

function! s:append(data) abort
function! s:tolines(data) abort
if type(a:data) == type([])
let l:lines = ''
for l:entry in a:data
call s:append(entry)
let l:lines .= s:tolines(l:entry)[1] . "\n"
endfor

return 'markdown'
return ['markdown', l:lines]
elseif type(a:data) == type('')
silent put =a:data

return 'markdown'
return ['markdown', a:data]
elseif type(a:data) == type({}) && has_key(a:data, 'language')
silent put ='```'.a:data.language
silent put =a:data.value
silent put ='```'

return 'markdown'
return ['markdown', '```' . a:data.language . "\n" . a:data.value . "\n```\n"]
elseif type(a:data) == type({}) && has_key(a:data, 'kind')
silent put =a:data.value

return a:data.kind ==? 'plaintext' ? 'text' : a:data.kind
return [a:data.kind ==? 'plaintext' ? 'text' : a:data.kind, a:data.value]
endif
return ['', '']
endfunction