I broke up with neovim....vim is my best friend now
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
let s:definition = {
|
||||
\ 'vimlsp': { -> exists('g:lsp_loaded') },
|
||||
\ 'lsc': { -> exists('g:loaded_lsc') },
|
||||
\ 'lcn': { -> exists('g:LanguageClient_serverCommands') },
|
||||
\ 'asyncomplete': { -> exists('g:asyncomplete_loaded') },
|
||||
\ 'mucomplete': { -> exists('g:loaded_mucomplete') },
|
||||
\ 'ddc': { -> s:runtimepath("autoload/ddc.vim") },
|
||||
\ 'yegappan_lsp': { -> s:runtimepath('autoload/lsp/lspserver.vim') },
|
||||
\ }
|
||||
|
||||
|
||||
let s:cache = {}
|
||||
|
||||
"
|
||||
" vsnip_integ#detection#definition
|
||||
"
|
||||
function! vsnip_integ#detection#definition() abort
|
||||
return copy(s:definition)
|
||||
endfunction
|
||||
|
||||
"
|
||||
" vsnip_integ#detection#exists
|
||||
"
|
||||
function! vsnip_integ#detection#exists(id) abort
|
||||
if !has_key(s:cache, a:id)
|
||||
let s:cache[a:id] = s:definition[a:id]()
|
||||
endif
|
||||
return s:cache[a:id]
|
||||
endfunction
|
||||
|
||||
"
|
||||
" runtimepath
|
||||
"
|
||||
function! s:runtimepath(path) abort
|
||||
return !empty(globpath(&runtimepath, a:path))
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
let s:attached = v:false
|
||||
|
||||
"
|
||||
" vsnip_integ#integration#attach
|
||||
"
|
||||
" TODO: improve initialization.
|
||||
"
|
||||
function! vsnip_integ#integration#attach() abort
|
||||
if s:attached
|
||||
return
|
||||
endif
|
||||
let s:attached = v:true
|
||||
|
||||
for l:name in keys(vsnip_integ#detection#definition())
|
||||
try
|
||||
if vsnip_integ#detection#exists(l:name)
|
||||
call vsnip_integ#integration#{l:name}#attach()
|
||||
endif
|
||||
catch /.*/
|
||||
if g:vsnip_integ_debug
|
||||
echomsg string([v:exception, v:throwpoint])
|
||||
endif
|
||||
endtry
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
function! vsnip_integ#integration#asyncomplete#attach() abort
|
||||
call asyncomplete#register_source(
|
||||
\ s:get_source_option({
|
||||
\ 'name': 'vsnip',
|
||||
\ 'whitelist': ['*'],
|
||||
\ 'completor': function('s:completor'),
|
||||
\ })
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
"
|
||||
" get_source_option
|
||||
"
|
||||
function! s:get_source_option(opts) abort
|
||||
let l:defaults = {
|
||||
\ 'name': 'vsnip',
|
||||
\ 'completor': function('s:completor'),
|
||||
\ 'whitelist': ['*']
|
||||
\ }
|
||||
return extend(l:defaults, a:opts)
|
||||
endfunction
|
||||
|
||||
"
|
||||
" completor
|
||||
"
|
||||
function! s:completor(opts, ctx) abort
|
||||
let l:before_line = getline('.')
|
||||
let l:idx = min([strlen(l:before_line), col('.') - 2])
|
||||
let l:idx = max([l:idx, 0])
|
||||
let l:before_line = l:before_line[0 : l:idx]
|
||||
|
||||
if len(matchstr(l:before_line, s:get_keyword_pattern() . '$')) < 1
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
call asyncomplete#complete(
|
||||
\ a:opts.name,
|
||||
\ a:ctx,
|
||||
\ a:ctx.col - strlen(matchstr(a:ctx.typed, '\k*$')),
|
||||
\ vsnip#get_complete_items(bufnr('%'))
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
"
|
||||
" get_keyword_pattern
|
||||
"
|
||||
function! s:get_keyword_pattern() abort
|
||||
let l:keywords = split(&iskeyword, ',')
|
||||
let l:keywords = filter(l:keywords, { _, k -> match(k, '\d\+-\d\+') == -1 })
|
||||
let l:keywords = filter(l:keywords, { _, k -> k !=# '@' })
|
||||
let l:pattern = '\%(' . join(map(l:keywords, { _, v -> '\V' . escape(v, '\') . '\m' }), '\|') . '\|\w\)*'
|
||||
return l:pattern
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
"
|
||||
" vsnip_integ#integration#lcn#attach
|
||||
"
|
||||
function! vsnip_integ#integration#lcn#attach() abort
|
||||
let g:LanguageClient_hasSnippetSupport = v:true
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
"
|
||||
" vsnip_integ#integration#lsc#attach
|
||||
"
|
||||
function! vsnip_integ#integration#lsc#attach() abort
|
||||
let g:lsc_enable_snippet_support = v:true
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"
|
||||
" vsnip_integ#integration#mucomplete#attach
|
||||
"
|
||||
function! vsnip_integ#integration#mucomplete#attach() abort
|
||||
call mucomplete#add_user_mapping('vsnip', "\<C-r>=vsnip_integ#integration#mucomplete#complete()\<CR>")
|
||||
endfunction
|
||||
|
||||
"
|
||||
" vsnip_integ#integration#mucomplete#complete
|
||||
"
|
||||
function! vsnip_integ#integration#mucomplete#complete() abort
|
||||
let l:before_line = getline('.')
|
||||
let l:idx = min([strlen(l:before_line), col('.') - 2])
|
||||
let l:idx = max([l:idx, 0])
|
||||
let l:before_line = l:before_line[0 : l:idx]
|
||||
let l:keyword = matchstr(l:before_line, '\k\+$')
|
||||
|
||||
if l:keyword == ''
|
||||
return ''
|
||||
endif
|
||||
|
||||
let l:candidates = vsnip#get_complete_items(bufnr('%'))
|
||||
let l:match = map(l:candidates, { _, val -> (l:keyword == val["word"][0:strlen(l:keyword)-1]) ? val : ''})
|
||||
|
||||
if !empty(l:candidates)
|
||||
call complete(col('.') - strlen(l:keyword), l:match)
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"
|
||||
" vsnip_integ#integration#vimlsp#attach
|
||||
"
|
||||
function! vsnip_integ#integration#vimlsp#attach() abort
|
||||
let g:lsp_text_edit_enabled = v:true
|
||||
let g:lsp_get_supported_capabilities = [function('s:get_supported_capabilities')]
|
||||
let g:lsp_snippet_expand = [{ option -> vsnip#anonymous(option.snippet) }]
|
||||
endfunction
|
||||
|
||||
"
|
||||
" get_supported_capabilities.
|
||||
"
|
||||
function! s:get_supported_capabilities(server_info) abort
|
||||
let l:capabilities = lsp#default_get_supported_capabilities(a:server_info)
|
||||
|
||||
if !has_key(l:capabilities, 'textDocument')
|
||||
let l:capabilities.textDocument = {}
|
||||
endif
|
||||
|
||||
if !has_key(l:capabilities.textDocument, 'completion')
|
||||
let l:capabilities.textDocument.completion = {}
|
||||
endif
|
||||
|
||||
if !has_key(l:capabilities.textDocument.completion, 'completionItem')
|
||||
let l:capabilities.textDocument.completion.completionItem = {}
|
||||
endif
|
||||
|
||||
let l:capabilities.textDocument.completion.completionItem.snippetSupport = v:true
|
||||
|
||||
return l:capabilities
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
"
|
||||
" vsnip_integ#integration#yegappan_lsp#attach
|
||||
"
|
||||
function! vsnip_integ#integration#yegappan_lsp#attach() abort
|
||||
call LspOptionsSet({ 'snippetSupport': v:true })
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user