3 # Functions related to displaying hover symbol information.
6 import './options.vim' as opt
8 # Util used to compute the hoverText from textDocument/hover reply
9 def GetHoverText(lspserver: dict<any>, hoverResult: any): list<any>
10 if hoverResult->empty()
15 if hoverResult.contents->type() == v:t_dict
16 && hoverResult.contents->has_key('kind')
17 if hoverResult.contents.kind == 'plaintext'
18 return [hoverResult.contents.value->split("\n"), 'text']
21 if hoverResult.contents.kind == 'markdown'
22 return [hoverResult.contents.value->split("\n"), 'lspgfm']
26 $'{strftime("%m/%d/%y %T")}: Unsupported hover contents kind ({hoverResult.contents.kind})'
32 if hoverResult.contents->type() == v:t_dict
33 && hoverResult.contents->has_key('value')
35 [$'``` {hoverResult.contents.language}']
36 + hoverResult.contents.value->split("\n")
43 if hoverResult.contents->type() == v:t_string
44 return [hoverResult.contents->split("\n"), 'lspgfm']
47 # interface MarkedString[]
48 if hoverResult.contents->type() == v:t_list
49 var hoverText: list<string> = []
50 for e in hoverResult.contents
51 if !hoverText->empty()
52 hoverText->extend(['- - -'])
55 if e->type() == v:t_string
56 hoverText->extend(e->split("\n"))
58 hoverText->extend([$'``` {e.language}'])
59 hoverText->extend(e.value->split("\n"))
60 hoverText->extend(['```'])
64 return [hoverText, 'lspgfm']
68 $'{strftime("%m/%d/%y %T")}: Unsupported hover reply ({hoverResult})'
73 # process the 'textDocument/hover' reply from the LSP server
74 # Result: Hover | null
75 export def HoverReply(lspserver: dict<any>, hoverResult: any, cmdmods: string): void
76 var [hoverText, hoverKind] = GetHoverText(lspserver, hoverResult)
80 if cmdmods !~ 'silent'
81 util.WarnMsg($'No documentation found for current keyword')
86 if opt.lspOptions.hoverInPreview
87 execute $':silent! {cmdmods} pedit LspHoverReply'
89 :setlocal buftype=nofile
90 :setlocal bufhidden=delete
91 bufnr()->deletebufline(1, '$')
94 exe $'setlocal ft={hoverKind}'
98 var winid = hoverText->popup_atcursor({moved: 'any',
103 border: [0, 1, 0, 1],
105 win_execute(winid, $'setlocal ft={hoverKind}')
109 # vim: tabstop=8 shiftwidth=2 softtabstop=2