]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/lsp/ui/vim/execute_command.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 '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / lsp / ui / vim / execute_command.vim
1 let s:commands = {}
2
3 "
4 " @param {name} = string
5 " @param {callback} = funcref
6 "
7 function! lsp#ui#vim#execute_command#_register(command_name, callback) abort
8   if has_key(s:commands, a:command_name)
9     throw printf('lsp#ui#vim#execute_command#_register_command: %s already registered.', a:command_name)
10   endif
11
12   let s:commands[a:command_name] = a:callback
13 endfunction
14
15 "
16 " TODO: This method does not handle any return value.
17 "
18 function! lsp#ui#vim#execute_command#_execute(params) abort
19   let l:command_name = a:params['command_name']
20   let l:command_args = get(a:params, 'command_args', v:null)
21   let l:server_name = get(a:params, 'server_name', '')
22   let l:bufnr = get(a:params, 'bufnr', -1)
23   let l:sync = get(a:params, 'sync', v:false)
24
25   " create command.
26   let l:command = { 'command': l:command_name }
27   if l:command_args isnot v:null
28     let l:command['arguments'] = l:command_args
29   endif
30
31   " execute command on local.
32   if has_key(s:commands, l:command_name)
33     try
34       call s:commands[l:command_name]({
35       \   'bufnr': l:bufnr,
36       \   'server_name': l:server_name,
37       \   'command': l:command,
38       \ })
39     catch /.*/
40       call lsp#utils#error(printf('Execute command failed: %s', string(a:params)))
41     endtry
42     return
43   endif
44
45   " execute command on server.
46   if !empty(l:server_name)
47     call lsp#send_request(l:server_name, {
48     \   'method': 'workspace/executeCommand',
49     \   'params': l:command,
50     \   'sync': l:sync,
51     \   'on_notification': function('s:handle_execute_command', [l:server_name, l:command]),
52     \ })
53   endif
54 endfunction
55
56 "
57 " handle workspace/executeCommand response
58 "
59 function! s:handle_execute_command(server_name, command, data) abort
60   if lsp#client#is_error(a:data['response'])
61     call lsp#utils#error('Execute command failed on ' . a:server_name . ': ' . string(a:command) . ' -> ' . string(a:data))
62   endif
63 endfunction
64