From: martin f. krafft Date: Tue, 8 Apr 2025 15:44:57 +0000 (+0200) Subject: Merge commit 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete... X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/0a7dcc812bf211a32009105099976052fca73be5?hp=-c Merge commit 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete-lsp' --- 0a7dcc812bf211a32009105099976052fca73be5 diff --combined .vim/bundle/asyncomplete-lsp/.gitattributes index 00000000,176a458f..176a458f mode 000000,100644..100644 --- a/.vim/bundle/asyncomplete-lsp/.gitattributes +++ b/.vim/bundle/asyncomplete-lsp/.gitattributes @@@ -1,0 -1,1 +1,1 @@@ + * text=auto diff --combined .vim/bundle/asyncomplete-lsp/.gitignore index 00000000,00000000..6e92f57d new file mode 100644 --- /dev/null +++ b/.vim/bundle/asyncomplete-lsp/.gitignore @@@ -1,0 -1,0 +1,1 @@@ ++tags diff --combined .vim/bundle/asyncomplete-lsp/LICENSE index 00000000,320f535c..320f535c mode 000000,100644..100644 --- a/.vim/bundle/asyncomplete-lsp/LICENSE +++ b/.vim/bundle/asyncomplete-lsp/LICENSE @@@ -1,0 -1,21 +1,21 @@@ + MIT License + + Copyright (c) 2022 Prabir Shrestha + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. diff --combined .vim/bundle/asyncomplete-lsp/README.md index 00000000,9e27bf50..9e27bf50 mode 000000,100644..100644 --- a/.vim/bundle/asyncomplete-lsp/README.md +++ b/.vim/bundle/asyncomplete-lsp/README.md @@@ -1,0 -1,12 +1,12 @@@ + LSP source for asyncomplete.vim vim-lsp + ======================================= + + Provide [Language Server Protocol](https://github.com/Microsoft/language-server-protocol) autocompletion source for [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim) and [vim-lsp](https://github.com/prabirshrestha/vim-lsp). + + ## Installing + Refer to asyncomplete.vim docs on Language Server Protocol at https://github.com/prabirshrestha/asyncomplete.vim#language-server-protocol-lsp. + + + ## License + + MIT diff --combined .vim/bundle/asyncomplete-lsp/plugin/asyncomplete-lsp.vim index 00000000,bc42d3d7..bc42d3d7 mode 000000,100644..100644 --- a/.vim/bundle/asyncomplete-lsp/plugin/asyncomplete-lsp.vim +++ b/.vim/bundle/asyncomplete-lsp/plugin/asyncomplete-lsp.vim @@@ -1,0 -1,103 +1,103 @@@ + if exists('g:asyncomplete_lsp_loaded') + finish + endif + let g:asyncomplete_lsp_loaded = 1 + + let s:servers = {} " { server_name: 1 } + + augroup asyncomplete_lsp + au! + au User lsp_server_init call s:server_initialized() + au User lsp_server_exit call s:server_exited() + augroup END + + function! s:server_initialized() abort + let l:server_names = lsp#get_server_names() + for l:server_name in l:server_names + if has_key(s:servers, l:server_name) + continue + endif + let l:init_capabilities = lsp#get_server_capabilities(l:server_name) + if !has_key(l:init_capabilities, 'completionProvider') + continue + endif + + let l:server = lsp#get_server_info(l:server_name) + let l:name = s:generate_asyncomplete_name(l:server_name) + let l:source_opt = { + \ 'name': l:name, + \ 'completor': function('s:completor', [l:server]), + \ } + if type(l:init_capabilities['completionProvider']) == type({}) && has_key(l:init_capabilities['completionProvider'], 'triggerCharacters') + let l:source_opt['triggers'] = { '*': l:init_capabilities['completionProvider']['triggerCharacters'] } + endif + if has_key(l:server, 'allowlist') + let l:source_opt['allowlist'] = l:server['allowlist'] + elseif has_key(l:server, 'whitelist') + let l:source_opt['allowlist'] = l:server['whitelist'] + endif + if has_key(l:server, 'blocklist') + let l:source_opt['blocklist'] = l:server['blocklist'] + elseif has_key(l:server, 'blacklist') + let l:source_opt['blocklist'] = l:server['blacklist'] + endif + if has_key(l:server, 'priority') + let l:source_opt['priority'] = l:server['priority'] + endif + call asyncomplete#register_source(l:source_opt) + let s:servers[l:server_name] = 1 + endfor + endfunction + + function! s:server_exited() abort + let l:server_names = lsp#get_server_names() + for l:server_name in l:server_names + if !has_key(s:servers, l:server_name) + continue + endif + let l:name = s:generate_asyncomplete_name(l:server_name) + if s:servers[l:server_name] + call asyncomplete#unregister_source(l:name) + endif + unlet s:servers[l:server_name] + endfor + endfunction + + function! s:generate_asyncomplete_name(server_name) abort + return 'asyncomplete_lsp_' . a:server_name + endfunction + + function! s:completor(server, opt, ctx) abort + let l:position = lsp#get_position() + call lsp#send_request(a:server['name'], { + \ 'method': 'textDocument/completion', + \ 'params': { + \ 'textDocument': lsp#get_text_document_identifier(), + \ 'position': l:position, + \ }, + \ 'on_notification': function('s:handle_completion', [a:server, l:position, a:opt, a:ctx]), + \ }) + endfunction + + function! s:handle_completion(server, position, opt, ctx, data) abort + if lsp#client#is_error(a:data) || !has_key(a:data, 'response') || !has_key(a:data['response'], 'result') + return + endif + + let l:options = { + \ 'server': a:server, + \ 'position': a:position, + \ 'response': a:data['response'], + \ } + + let l:completion_result = lsp#omni#get_vim_completion_items(l:options) + + let l:col = a:ctx['col'] + let l:typed = a:ctx['typed'] + let l:kw = matchstr(l:typed, get(b:, 'asyncomplete_refresh_pattern', '\k\+$')) + let l:kwlen = len(l:kw) + let l:startcol = l:col - l:kwlen + let l:startcol = min([l:startcol, get(l:completion_result, 'startcol', l:startcol)]) + + call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:completion_result['items'], l:completion_result['incomplete']) + endfunction