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.
1 " https://microsoft.github.io/language-server-protocol/specification#workspace_symbol
3 " bufnr: bufnr('%') " optional
4 " server - 'server_name' " optional
7 function! lsp#internal#workspace_symbol#search#do(options) abort
8 if has_key(a:options, 'server')
9 let l:servers = [a:options['server']]
11 let l:servers = filter(lsp#get_allowed_servers(), 'lsp#capabilities#has_document_symbol_provider(v:val)')
14 if len(l:servers) == 0
15 echom 'textDocument/workspaceSymbol not supported'
16 call lsp#utils#error('textDocument/workspaceSymbol not supported')
20 redraw | echo 'Retrieving workspace symbols ...'
22 let l:TextChangeSubject = lsp#callbag#makeSubject()
24 " use callbag debounce instead of quickpick debounce
25 call lsp#internal#ui#quickpick#open({
27 \ 'input': get(a:options, 'query', ''),
30 \ 'on_change': function('s:on_change', [l:TextChangeSubject]),
31 \ 'on_accept': function('s:on_accept'),
32 \ 'on_close': function('s:on_close'),
35 let s:Dispose = lsp#callbag#pipe(
36 \ l:TextChangeSubject,
37 \ lsp#callbag#debounceTime(250),
38 \ lsp#callbag#distinctUntilChanged(),
39 \ lsp#callbag#switchMap({query->
41 \ lsp#callbag#fromList(l:servers),
42 \ lsp#callbag#tap({_->lsp#internal#ui#quickpick#busy(1)}),
43 \ lsp#callbag#flatMap({server->
45 \ lsp#request(server, {
46 \ 'method': 'workspace/symbol',
51 \ lsp#callbag#map({x->{'server': server, 'request': x['request'], 'response': x['response']}}),
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)}}),
59 \ lsp#callbag#subscribe({
60 \ 'error': {e->s:on_error(e)},
63 " Notify empty query. Some servers may not return results when query is empty
64 call l:TextChangeSubject(1, '')
67 function! s:on_change(TextChangeSubject, data, ...) abort
68 call a:TextChangeSubject(1, a:data['input'])
71 function! s:update_ui_items(x) abort
74 let l:items += lsp#ui#vim#utils#symbols_to_loc_list(l:i['server'], l:i)
76 call lsp#internal#ui#quickpick#items(l:items)
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], '')
84 function! s:on_close(...) abort
85 if exists('s:Dispose')
91 function! s:on_error(e) abort
92 call lsp#internal#ui#quickpick#close()
93 call lsp#log('LspWorkspaceSymbolSearch error', a:e)