|
| 1 | +" Author: liuchengxu <[email protected]> |
| 2 | + |
| 3 | +scriptencoding utf-8 |
| 4 | + |
| 5 | +let s:save_cpo = &cpoptions |
| 6 | +set cpoptions&vim |
| 7 | + |
| 8 | +function! s:jump_to(location) abort |
| 9 | + execute 'edit' a:location.path |
| 10 | + noautocmd call setpos('.', [bufnr(''), a:location.row, a:location.column, 0]) |
| 11 | + normal! zz |
| 12 | +endfunction |
| 13 | + |
| 14 | +function! s:to_quickfix_entry(location) abort |
| 15 | + return { 'filename': a:location.path, 'lnum': a:location.row, 'col': a:location.column, 'text': a:location.text } |
| 16 | +endfunction |
| 17 | + |
| 18 | +function! clap#plugin#lsp#handle_locations(id, locations) abort |
| 19 | + if len(a:locations) == 1 |
| 20 | + call s:jump_to(a:locations[0]) |
| 21 | + return |
| 22 | + endif |
| 23 | + |
| 24 | + let mode = 'quickfix' |
| 25 | + |
| 26 | + if mode ==# 'quickfix' |
| 27 | + let entries = map(a:locations, 's:to_quickfix_entry(v:val)') |
| 28 | + call clap#sink#open_quickfix(entries) |
| 29 | + else |
| 30 | + let provider = { |
| 31 | + \ 'id': a:id, |
| 32 | + \ 'source': map(a:locations, 'printf("%s:%s:%s", v:val["path"], v:val["row"], v:val["column"])'), |
| 33 | + \ 'sink': 'e', |
| 34 | + \ } |
| 35 | + |
| 36 | + call clap#run(provider) |
| 37 | + endif |
| 38 | +endfunction |
| 39 | + |
| 40 | +function! clap#plugin#lsp#open_picker() abort |
| 41 | + let provider = { |
| 42 | + \ 'id': 'lsp', |
| 43 | + \ 'on_typed': { -> clap#client#notify_provider('on_typed') }, |
| 44 | + \ 'sink': 'e', |
| 45 | + \ } |
| 46 | + call clap#run(provider) |
| 47 | +endfunction |
| 48 | + |
| 49 | +function! clap#plugin#lsp#provider_context() abort |
| 50 | + let params = { |
| 51 | + \ 'provider_id': 'lsp', |
| 52 | + \ 'input': { 'bufnr': g:clap.input.bufnr, 'winid': g:clap.input.winid }, |
| 53 | + \ 'start': { 'bufnr': g:clap.start.bufnr, 'winid': g:clap.start.winid }, |
| 54 | + \ 'display': { 'bufnr': g:clap.display.bufnr, 'winid': g:clap.display.winid }, |
| 55 | + \ 'cwd': clap#rooter#working_dir(), |
| 56 | + \ 'icon': g:clap_enable_icon ? get(g:clap.provider._(), 'icon', 'Null') : 'Null', |
| 57 | + \ 'no_cache': has_key(g:clap.context, 'no-cache') ? v:true : v:false, |
| 58 | + \ 'start_buffer_path': expand('#'.g:clap.start.bufnr.':p'), |
| 59 | + \ 'source_is_list': v:false, |
| 60 | + \ } |
| 61 | +endfunction |
| 62 | + |
| 63 | +let &cpoptions = s:save_cpo |
| 64 | +unlet s:save_cpo |
0 commit comments