]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/lsp/internal/show_message_request.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:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / lsp / internal / show_message_request.vim
1 function! lsp#internal#show_message_request#_enable() abort
2     if !g:lsp_show_message_request_enabled | return | endif
3     let s:Dispose = lsp#callbag#pipe(
4             \ lsp#stream(),
5             \ lsp#callbag#filter({x->
6             \   g:lsp_show_message_request_enabled &&
7             \   has_key(x, 'request') && !has_key(x, 'response') &&
8             \   has_key(x['request'], 'method') && x['request']['method'] ==# 'window/showMessageRequest'
9             \ }),
10             \ lsp#callbag#map({x->s:show_message_request(x['server'], x['request'])}),
11             \ lsp#callbag#map({x->s:send_message_response(x['server'], x['request'], x['action'])}),
12             \ lsp#callbag#flatten(),
13             \ lsp#callbag#materialize(),
14             \ lsp#callbag#subscribe({ 'error': function('s:on_error') }),
15             \ )
16 endfunction
17
18 function! lsp#internal#show_message_request#_disable() abort
19     if exists('s:Dispose')
20         call s:Dispose()
21         unlet s:Dispose
22     endif
23 endfunction
24
25 function! s:on_error(e) abort
26     call lsp#log('lsp#internal#show_message_request error', a:e)
27     if exists('s:Dispose')
28         call s:Dispose()
29         unlet s:Dispose
30     endif
31 endfunction
32
33 function! s:show_message_request(server_name, request) abort
34     let l:params = a:request['params']
35
36     let l:selected_action = v:null
37
38     if has_key(l:params, 'actions') && !empty(l:params['actions'])
39         let l:options = map(copy(l:params['actions']), {i, action ->
40             \   printf('%d - [%s] %s', i + 1, a:server_name, action['title'])
41             \ })
42         let l:index = inputlist([l:params['message']] + l:options)
43         if l:index > 0 && l:index <= len(l:index)
44             let l:selected_action = l:params['actions'][l:index - 1]
45         endif
46     else
47         echom l:params['message']
48     endif
49
50     return { 'server': a:server_name, 'request': a:request, 'action': l:selected_action }
51 endfunction
52
53 function! s:send_message_response(server_name, request, action) abort
54     return lsp#request(a:server_name, {
55         \ 'id': a:request['id'],
56         \ 'result': a:action
57         \})
58 endfunction