[[plugins]]
repo = 'Shougo/ddc.vim'
depends = ['context_filetype.vim', 'denops.vim', 'pum.vim']
on_event = 'InsertEnter'
hook_source = '''
  inoremap <silent><expr> <C-l> ddc#complete_common_string()

  call ddc#custom#patch_global(
      \ 'sources', ['around', 'neosnippet', 'rg', 'file']
      \ )

  call ddc#custom#patch_global('sourceOptions', {
      \ '_': {
      \   'ignoreCase': v:true,
      \   'matchers': ['matcher_head'],
      \   'sorters': ['sorter_rank'],
      \ },
      \ 'around': {
      \   'mark': 'A',
      \   'matchers': ['matcher_head', 'matcher_length'],
      \ },
      \ 'cmdline': {
      \   'mark': 'CmdL',
      \   'forceCompletionPattern': '\S/\S*',
      \ },
      \ 'cmdline-history': {
      \   'mark': 'Hist',
      \   'sorters': [],
      \ },
      \ 'rg': {
      \   'mark': 'rg',
      \   'matchers': ['matcher_head', 'matcher_length'],
      \   'minAutoCompleteLength': 4,
      \ },
      \ 'neosnippet': {
      \   'mark': 'ns',
      \   'dup':  'true',
      \ },
      \ 'vsnip': {
      \    'mark': "vs",
      \    'dup': 'true',
      \ },
      \ 'nvim-lsp': {
      \   'mark': 'LSP',
      \   'forceCompletionPattern': '\.\w*|:\w*|->\w*'
      \ },
      \ 'file': {
      \   'mark': 'F',
      \   'isVolatile': v:true,
      \   'minAutoCompleteLength': 1000,
      \   'forceCompletionPattern': '\S/\S*'
      \ },
      \ })
  call ddc#custom#patch_filetype(['ruby', 'typescript', 'dart', 'swift'], 'sources', has('nvim') ?
  \ ['nvim-lsp', 'vsnip', 'around', 'neosnippet', 'file'] : ['vsnip', 'around', 'neosnippet', 'file']
  \ )

  " Use pum.vim

  call ddc#custom#patch_global('completionMenu', 'pum.vim')

  call ddc#custom#patch_global('autoCompleteEvents', [
    \ 'InsertEnter', 'TextChangedI', 'TextChangedP',
    \ 'CmdlineEnter', 'CmdlineChanged',
    \ ])
  inoremap <silent><expr> <TAB>
        \ pum#visible() ? '<Cmd>call pum#map#insert_relative(+1)<CR>' :
        \ (col('.') <= 1 <Bar><Bar> getline('.')[col('.') - 2] =~# '\s') ?
        \ '<TAB>' : ddc#manual_complete()
  inoremap <S-Tab> <Cmd>call pum#map#insert_relative(-1)<CR>
  inoremap <C-n>   <Cmd>call pum#map#select_relative(+1)<CR>
  inoremap <C-p>   <Cmd>call pum#map#select_relative(-1)<CR>
  inoremap <C-y>   <Cmd>call pum#map#confirm()<CR>
  inoremap <C-e>   <Cmd>call pum#map#cancel()<CR>

"   inoremap <silent><expr> <TAB>
"   \ pumvisible() ? '<C-n>' :
"   \ (col('.') <= 1 <Bar><Bar> getline('.')[col('.') - 2] =~# '\s') ?
"   \ '<TAB>' : ddc#map#manual_complete()
"  inoremap <expr><S-TAB>  pumvisible() ? '<C-p>' : '<C-h>'

  call ddc#enable()
'''
hook_add = '''

nnoremap :       <Cmd>call CommandlinePre()<CR>:

function! CommandlinePre() abort
  " Note: It disables default command line completion!
  cnoremap <expr> <Tab>
  \ pum#visible() ? '<Cmd>call pum#map#insert_relative(+1)<CR>' :
  \ ddc#manual_complete()
  cnoremap <S-Tab> <Cmd>call pum#map#insert_relative(-1)<CR>
  cnoremap <C-y>   <Cmd>call pum#map#confirm()<CR>
  cnoremap <C-e>   <Cmd>call pum#map#cancel()<CR>

  " Overwrite sources
  let s:prev_buffer_config = ddc#custom#get_buffer()
  call ddc#custom#patch_buffer('sources',
          \ ['cmdline', 'cmdline-history', 'around'])

  autocmd User DDCCmdlineLeave ++once call CommandlinePost()

  " Enable command line completion
  call ddc#enable_cmdline_completion()
  call ddc#enable()
endfunction

function! CommandlinePost() abort
  " Restore sources
  call ddc#custom#set_buffer(s:prev_buffer_config)
  cunmap <Tab>
endfunction
'''

[[plugins]]
repo = 'Shougo/ddc-sorter_rank'
on_source = 'ddc.vim'

[[plugins]]
repo = 'Shougo/ddc-matcher_head'
on_source = 'ddc.vim'

[[plugins]]
repo = 'Shougo/ddc-matcher_length'
on_source = 'ddc.vim'

[[plugins]]
repo = 'Shougo/ddc-around'
on_source = 'ddc.vim'

[[plugins]]
repo = 'Shougo/ddc-rg'
on_source = 'ddc.vim'

[[plugins]]
repo = 'Shougo/ddc-nvim-lsp'
on_source = 'nvim-lspconfig'

[[plugins]]
repo = 'LumaKernel/ddc-file'
on_source = 'ddc.vim'

[[plugins]]
repo = 'neovim/nvim-lspconfig'
on_ft = ['ruby','typescript', 'dart', 'swift']
if = 'has("nvim")'
depends = 'ddc.vim'
hook_source = '''
  lua << EOF
    local capabilities = vim.lsp.protocol.make_client_capabilities()
    capabilities.textDocument.completion.completionItem.snippetSupport = true

    require'lspconfig'.solargraph.setup{}
    require'lspconfig'.denols.setup{}
    require'lspconfig'.dartls.setup{}
    require'lspconfig'.sourcekit.setup{capabilities = capabilities}
EOF
'''

[[plugins]]
repo = 'matsui54/denops-popup-preview.vim'
on_source = 'ddc.vim'
on_event = 'InsertEnter'
hook_source = '''
  let g:popup_preview_config = {
	    \ 'delay': 30,
        \ 'maxWidth': 20,
        \ 'winblend': 'winblend',
	    \ }
  call popup_preview#enable()
'''

[[plugins]]
repo = 'matsui54/denops-signature_help'
on_source = 'ddc.vim'
on_event = 'InsertEnter'
hook_source = '''
	let g:signature_help_config = {
        \ 'style': 'full',
        \ 'border': v:true,
        \ }
  call signature_help#enable()
'''

[[plugins]]
repo = 'hrsh7th/vim-vsnip'
depends = ['vim-vsnip-integ', 'friendly-snippets']
on_source = 'ddc.vim'
on_event = 'InsertEnter'
hook_add = '''
" Expand
imap <expr> <C-l> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-l>'
smap <expr> <C-l> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-l>'
" Jump forward or backward
imap <expr> <C-f> vsnip#jumpable(1)  ? '<Plug>(vsnip-jump-next)' : '<C-f>'
smap <expr> <C-f> vsnip#jumpable(1)  ? '<Plug>(vsnip-jump-next)' : '<C-f>'
imap <expr> <C-b> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<C-b>'
smap <expr> <C-b> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<C-b>'
let g:vsnip_snippet_dir = expand('~/dotfiles/vim/snippets')
autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item)
'''

[[plugins]]
repo = 'hrsh7th/vim-vsnip-integ'

[[plugins]]
repo = 'rafamadriz/friendly-snippets'

[[plugins]]
repo = 'Shougo/neosnippet.vim'
depends = ['neosnippet-snippets', 'context_filetype.vim','ddc.vim']
on_event = 'InsertCharPre'
on_ft = 'snippet'
hook_source = '''
    imap <silent><C-k>     <Plug>(neosnippet_jump_or_expand)
    smap <silent><C-k>     <Plug>(neosnippet_jump_or_expand)
    xmap <silent><C-k>     <Plug>(neosnippet_expand_target)
    let g:neosnippet#enable_snipmate_compatibility = 1
    let g:neosnippet#enable_completed_snippet = 1
    let g:neosnippet#expand_word_boundary = 1
    let g:neosnippet#snippets_directory = '~/.vim/snippets'
    " if has('conceal')
    "     set conceallevel=0
    " endif
'''

# pum.vim
[[plugins]]
repo = 'Shougo/pum.vim'

[[plugins]]
repo = 'Shougo/ddc-cmdline'
on_source = 'ddc.vim'

[[plugins]]
repo = 'Shougo/ddc-cmdline-history'
on_source = 'ddc.vim'