]> git.madduck.net Git - etc/vim.git/commitdiff

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 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
authormartin f. krafft <madduck@madduck.net>
Tue, 8 Apr 2025 15:44:57 +0000 (17:44 +0200)
committermartin f. krafft <madduck@madduck.net>
Tue, 8 Apr 2025 15:44:57 +0000 (17:44 +0200)
1  2 
.vim/bundle/asyncomplete-lsp/.gitattributes
.vim/bundle/asyncomplete-lsp/.gitignore
.vim/bundle/asyncomplete-lsp/LICENSE
.vim/bundle/asyncomplete-lsp/README.md
.vim/bundle/asyncomplete-lsp/plugin/asyncomplete-lsp.vim

index 0000000000000000000000000000000000000000,176a458f94e0ea5272ce67c36bf30b6be9caf623..176a458f94e0ea5272ce67c36bf30b6be9caf623
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1 +1,1 @@@
+ * text=auto
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..6e92f57d4647a41113f50e94f59047114f7e1d81
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,1 @@@
++tags
index 0000000000000000000000000000000000000000,320f535cbbf8c209c7821fa18c0ec5a3f2062883..320f535cbbf8c209c7821fa18c0ec5a3f2062883
mode 000000,100644..100644
--- /dev/null
@@@ -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.
index 0000000000000000000000000000000000000000,9e27bf509d5461ba173787e164257fa460298ccb..9e27bf509d5461ba173787e164257fa460298ccb
mode 000000,100644..100644
--- /dev/null
@@@ -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
index 0000000000000000000000000000000000000000,bc42d3d7491ed2334b1ab43613fbb65109366e9e..bc42d3d7491ed2334b1ab43613fbb65109366e9e
mode 000000,100644..100644
--- /dev/null
@@@ -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