]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/lsp/internal/workspace_symbol/search.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 / workspace_symbol / search.vim
1 " https://microsoft.github.io/language-server-protocol/specification#workspace_symbol
2 " options - {
3 "   bufnr: bufnr('%')       " optional
4 "   server - 'server_name'  " optional
5 "   query: ''               " optional
6 " }
7 function! lsp#internal#workspace_symbol#search#do(options) abort
8     if has_key(a:options, 'server')
9         let l:servers = [a:options['server']]
10     else
11         let l:servers = filter(lsp#get_allowed_servers(), 'lsp#capabilities#has_document_symbol_provider(v:val)')
12     endif
13
14     if len(l:servers) == 0
15         echom 'textDocument/workspaceSymbol not supported'
16         call lsp#utils#error('textDocument/workspaceSymbol not supported')
17         return
18     endif
19
20     redraw | echo 'Retrieving workspace symbols ...'
21
22     let l:TextChangeSubject = lsp#callbag#makeSubject()
23
24     " use callbag debounce instead of quickpick debounce
25     call lsp#internal#ui#quickpick#open({
26         \ 'items': [],
27         \ 'input': get(a:options, 'query', ''),
28         \ 'key': 'text',
29         \ 'debounce': 0,
30         \ 'on_change': function('s:on_change', [l:TextChangeSubject]),
31         \ 'on_accept': function('s:on_accept'),
32         \ 'on_close': function('s:on_close'),
33         \ })
34
35     let s:Dispose = lsp#callbag#pipe(
36         \ l:TextChangeSubject,
37         \ lsp#callbag#debounceTime(250),
38         \ lsp#callbag#distinctUntilChanged(),
39         \ lsp#callbag#switchMap({query->
40         \   lsp#callbag#pipe(
41         \       lsp#callbag#fromList(l:servers),
42         \       lsp#callbag#tap({_->lsp#internal#ui#quickpick#busy(1)}),
43         \       lsp#callbag#flatMap({server->
44         \           lsp#callbag#pipe(
45         \               lsp#request(server, {
46         \                   'method': 'workspace/symbol',
47         \                   'params': {
48         \                       'query': query
49         \                   }
50         \               }),
51         \               lsp#callbag#map({x->{'server': server, 'request': x['request'], 'response': x['response']}}),
52         \          )
53         \       }),
54         \       lsp#callbag#scan({acc, curr->add(acc, curr)}, []),
55         \       lsp#callbag#tap({x->s:update_ui_items(x)}),
56         \       lsp#callbag#tap({'complete': {->lsp#internal#ui#quickpick#busy(0)}}),
57         \   )
58         \ }),
59         \ lsp#callbag#subscribe({
60         \   'error': {e->s:on_error(e)},
61         \ }),
62         \ )
63     " Notify empty query. Some servers may not return results when query is empty
64     call l:TextChangeSubject(1, '')
65 endfunction
66
67 function! s:on_change(TextChangeSubject, data, ...) abort
68     call a:TextChangeSubject(1, a:data['input'])
69 endfunction
70
71 function! s:update_ui_items(x) abort
72     let l:items = []
73     for l:i in a:x
74         let l:items += lsp#ui#vim#utils#symbols_to_loc_list(l:i['server'], l:i)
75     endfor
76     call lsp#internal#ui#quickpick#items(l:items)
77 endfunction
78
79 function! s:on_accept(data, name) abort
80     call lsp#internal#ui#quickpick#close()
81     call lsp#utils#location#_open_vim_list_item(a:data['items'][0], '')
82 endfunction
83
84 function! s:on_close(...) abort
85     if exists('s:Dispose')
86         call s:Dispose()
87         unlet s:Dispose
88     endif
89 endfunction
90
91 function! s:on_error(e) abort
92     call lsp#internal#ui#quickpick#close()
93     call lsp#log('LspWorkspaceSymbolSearch error', a:e)
94 endfunction