Create preview window instead of using quickfix list (#78)

* Create preview window instead of using quickfix list

This removes from us burden of providing formatting for content as this
is now simple as setting proper filetype.

* Create custom filetype for preview window

This will allow users to provide their own mappings and features in
hover window easily.

* Add proper statusline for LSP Hover

* Guard and undo_ftplugin

* Support all LSP hover syntaxes
This commit is contained in:
Łukasz Jan Niemier
2018-01-01 22:29:50 +01:00
committed by Prabir Shrestha
parent a15344352f
commit 203d682e30
6 changed files with 87 additions and 47 deletions

View File

@@ -0,0 +1,38 @@
function! lsp#ui#vim#output#preview(data) abort
" Close any previously opened preview window
pclose
execute &previewheight.'new'
let l:ft = s:append(a:data)
" Delete first empty line
0delete
setlocal readonly nomodifiable
let &l:filetype = l:ft . '.lsp-hover'
endfunction
function! s:append(data) abort
if type(a:data) == type([])
for l:entry in a:data
call s:append(entry)
endfor
return 'markdown'
elseif type(a:data) == type('')
put =a:data
return 'markdown'
elseif type(a:data) == type({}) && has_key(a:data, 'language')
put ='```'.a:data.language
put =a:data.value
put ='```'
return 'markdown'
elseif type(a:data) == type({}) && has_key(a:data, 'kind')
put =a:data.value
return a:data.kind == 'plaintext' ? 'text' : a:data.kind
endif
endfunction