This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhover.vim
65 lines (54 loc) · 1.95 KB
/
hover.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function! langserver#hover#callback(id, data, event) abort
let l:parsed_data = langserver#callbacks#data(a:id, a:data, a:event)
if langserver#util#null_check(l:parsed_data)
call langserver#hover#display([], [
\ {
\ 'language': 'LSP',
\ 'value': 'Unable to retrieve hover information'
\ },
\ ],
\ )
return
endif
if l:parsed_data == {}
return
endif
" {'data': {'textDocument/hover': {'range': {'end': {'character': 20, 'line': 44}, 'start': {'character': 9, 'line': 44}}, 'contents': [{'language': 'go', 'value': 'type LangHandler struct'}, {'language': 'markdown', 'value': 'LangHandler is a Go language server LSP/JSON-RPC handler.'}]}}, 'type': 'result'}
if has_key(l:parsed_data, 'range')
let l:range = l:parsed_data['range']
else
let l:range = {}
endif
let l:data = l:parsed_data['contents']
call langserver#hover#display(l:range, l:data)
endfunction
function! langserver#hover#request() abort
return langserver#client#send(langserver#util#get_lsp_id(), {
\ 'method': 'textDocument/hover',
\ 'params': langserver#util#get_text_document_position_params(),
\ 'on_notification': {
\ 'callback': function('langserver#hover#callback'),
\ },
\ })
endfunction
function! langserver#hover#display(range, data) abort
if !empty(a:range)
let s:my_last_highlight = matchaddpos('WarningMsg', langserver#highlight#matchaddpos_range(a:range))
endif
let l:hover_string = ''
for l:explanation in a:data
let l:hover_string .= printf("%s: %s\n",
\ l:explanation['language'],
\ l:explanation['value'],
\ )
endfor
echo l:hover_string
if !empty(a:range)
return timer_start(3000, function('s:delete_highlight'))
endif
endfunction
function! s:delete_highlight(timer_id) abort
if exists('s:my_last_highlight')
silent! call matchdelete(s:my_last_highlight)
endif
endfunction