]> git.madduck.net Git - etc/vim.git/blob - autoload/lsp/internal/ui/popupmenu.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/vim-lsp/' content from commit 04428c92
[etc/vim.git] / autoload / lsp / internal / ui / popupmenu.vim
1 let s:Markdown = vital#lsp#import('VS.Vim.Syntax.Markdown')
2 let s:Window = vital#lsp#import('VS.Vim.Window')
3
4 function! lsp#internal#ui#popupmenu#open(opt) abort
5     let l:Callback = remove(a:opt, 'callback')
6     let l:items = remove(a:opt, 'items')
7
8     let l:items_with_shortcuts= map(l:items, {
9         \   idx, item -> ((idx < 9) ? '['.(idx+1).'] ' : '').item
10         \ })
11
12     function! Filter(id, key) abort closure
13         if a:key >= 1 && a:key <= len(l:items)
14             call popup_close(a:id, a:key)
15         elseif a:key ==# "\<C-j>"
16             call win_execute(a:id, 'normal! j')
17         elseif a:key ==# "\<C-k>"
18             call win_execute(a:id, 'normal! k')
19         else
20             return popup_filter_menu(a:id, a:key)
21         endif
22
23         return v:true
24     endfunction
25
26     let l:popup_opt = extend({
27         \   'callback': funcref('s:callback', [l:Callback]),
28         \   'filter': funcref('Filter'),
29         \ }, a:opt)
30
31     let l:winid = popup_menu(l:items_with_shortcuts, l:popup_opt)
32     call s:Window.do(l:winid, { -> s:Markdown.apply() })
33     execute('doautocmd <nomodeline> User lsp_float_opened')
34 endfunction
35
36 function! s:callback(callback, id, selected) abort
37     call a:callback(a:id, a:selected)
38     execute('doautocmd <nomodeline> User lsp_float_closed')
39 endfunction