1 " Custom statusline report
 
   2 function! CocStatus() abort
 
   3   let info = get(b:, 'coc_diagnostic_info', {})
 
   4   if empty(info) | return '' | endif
 
   6   if get(info, 'warning', 0)
 
   7     call add(msgs, 'W' . info['warning'])
 
   9   if get(info, 'information', 0)
 
  10     call add(msgs, 'I' . info['information'])
 
  12   if get(info, 'hint', 0)
 
  13     call add(msgs, 'H' . info['hint'])
 
  15   return join(msgs, ' ') . ' ' . get(g:, 'coc_status', '')
 
  17 function! CocStatusDiagnosticError() abort
 
  18   let info = get(b:, 'coc_diagnostic_info', {})
 
  19   if !empty(info) && get(info, 'error', 0)
 
  20     return ('E' . info['error'])
 
  24 " Refresh statusline when g:coc_status changes
 
  25 autocmd User CocStatusChange let &statusline=&statusline
 
  26 "autocmd CursorHold let &statusline=&statusline
 
  28 " Get correct comment highlighting in coc-settings.json
 
  29 autocmd FileType json syntax match Comment +\/\/.\+$+
 
  31 hi CocErrorFloat ctermfg=darkred
 
  32 hi CocErrorSign term=standout ctermfg=15 ctermbg=1 guifg=White guibg=Red
 
  33 hi CocWarningSign term=standout ctermfg=15 ctermbg=130 guifg=White guibg=Orange
 
  34 "hi! link CocErrorSign ErrorMsg
 
  35 "hi! link CocWarningSign WarningMsg
 
  36 hi CocFloating ctermbg=gray ctermfg=black
 
  37 hi CocHintSign ctermbg=gray ctermfg=black
 
  38 hi CocInfoSign ctermbg=darkblue ctermfg=black
 
  39 " Some servers have issues with backup files, see #649.
 
  42 " Give more space for displaying messages.
 
  46 set completeopt=noinsert,noselect,menuone
 
  47 " Don't pass messages to |ins-completion-menu|.
 
  49 " Use tab for trigger completion with characters ahead and navigate.
 
  50 " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
 
  51 " other plugin before putting this into your config.
 
  52 inoremap <silent><expr> <TAB>
 
  53  \ pumvisible() ? "\<C-n>" :
 
  54  \ <SID>check_back_space() ? "\<TAB>" :
 
  56 function! s:check_back_space() abort
 
  57         let col = col('.') - 1
 
  58         return !col || getline('.')[col - 1] =~# '\s'
 
  61 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
 
  63 " Use <c-space> to trigger completion.
 
  64 inoremap <silent><expr> <c-space> coc#refresh()
 
  66 " Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
 
  67 " Coc only does snippet and additional edit on confirm.
 
  68 if has('patch8.1.1068')
 
  69         " Use `complete_info` if your (Neo)Vim version supports it.
 
  70         inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
 
  72         imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
 
  75 " Use `[g` and `]g` to navigate diagnostics
 
  76 "nmap <silent> [g <Plug>(coc-diagnostic-prev)
 
  77 "nmap <silent> ]g <Plug>(coc-diagnostic-next)
 
  79 " GoTo code navigation.
 
  80 nmap <silent> gd <Plug>(coc-definition)
 
  81 nmap <silent> gr <Plug>(coc-references)
 
  82 " Do not seem to work for haskell-ide-engine
 
  83 nmap <silent> gy <Plug>(coc-type-definition)
 
  84 nmap <silent> gi <Plug>(coc-implementation)
 
  86 " Use H to show documentation in preview window.
 
  87 nnoremap <silent> H :call <SID>show_documentation()<CR>
 
  88 function! s:show_documentation()
 
  89         if (index(['vim','help'], &filetype) >= 0)
 
  90                 execute 'h '.expand('<cword>')
 
  92                 call CocAction('doHover')
 
  96 " Escape hides floating window
 
  97 nmap <silent> <c-[> <esc>:noh<cr><Plug>(coc-float-hide)
 
  99 " Highlight the symbol and its references when holding the cursor.
 
 100 autocmd CursorHold * silent call CocActionAsync('highlight')
 
 103 nmap <leader>rn <Plug>(coc-rename)
 
 105 " Formatting selected code.
 
 106 xmap <leader>f  <Plug>(coc-format-selected)
 
 107 nmap <leader>f  <Plug>(coc-format-selected)
 
 111         " Setup formatexpr specified filetype(s).
 
 112         autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
 
 113         " Update signature help on jump placeholder.
 
 114         autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
 
 117 " Applying codeAction to the selected region.
 
 118 " Example: `<leader>aap` for current paragraph
 
 119 xmap <leader>a  <Plug>(coc-codeaction-selected)
 
 120 nmap <leader>a  <Plug>(coc-codeaction-selected)
 
 122 " Remap keys for applying codeAction to the current line.
 
 123 nmap <leader>al  <Plug>(coc-codeaction)
 
 124 " Apply AutoFix to problem on the current line.
 
 125 nmap <leader>qf  <Plug>(coc-fix-current)
 
 127 " Introduce function text object
 
 128 " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
 
 129 xmap if <Plug>(coc-funcobj-i)
 
 130 xmap af <Plug>(coc-funcobj-a)
 
 131 omap if <Plug>(coc-funcobj-i)
 
 132 omap af <Plug>(coc-funcobj-a)
 
 134 " Use <TAB> for selections ranges.
 
 135 " NOTE: Requires 'textDocument/selectionRange' support from the language server.
 
 136 " coc-tsserver, coc-python are the examples of servers that support it.
 
 137 "nmap <silent> <TAB> <Plug>(coc-range-select)
 
 138 "xmap <silent> <TAB> <Plug>(coc-range-select)
 
 140 " Add `:Format` command to format current buffer.
 
 141 command! -nargs=0 Format :call CocAction('format')
 
 142 " Add `:Fold` command to fold current buffer.
 
 143 command! -nargs=? Fold :call CocAction('fold', <f-args>)
 
 144 command! -nargs=? Unfold :0,$foldopen
 
 145 " Add `:OR` command for organize imports of the current buffer.
 
 146 command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
 
 149 " Show all diagnostics.
 
 150 nnoremap <silent> <space>fa  :<C-u>CocList diagnostics<cr>
 
 152 nnoremap <silent> <leader>fe  :<C-u>CocList extensions<cr>
 
 154 nnoremap <silent> <leader>fc  :<C-u>CocList commands<cr>
 
 155 " Find symbol of current document.
 
 156 nnoremap <silent> <leader>fo  :<C-u>CocList outline<cr>
 
 157 " Search workspace symbols.
 
 158 nnoremap <silent> <leader>fs  :<C-u>CocList -I symbols<cr>
 
 159 " Do default action for next item in the last list.
 
 160 nnoremap <silent> <leader>fj  :<C-u>CocNext<CR>
 
 161 " Do default action for previous item in the last list.
 
 162 nnoremap <silent> <leader>fk  :<C-u>CocPrev<CR>
 
 163 " Resume latest coc list.
 
 164 nnoremap <silent> <leader>fp  :<C-u>CocListResume<CR>
 
 166 nnoremap <silent> <leader>ff  :<C-u>CocList files<CR>
 
 167 " List all errors (bugs).
 
 168 nnoremap <silent> <leader>fb :<C-u>CocList locationlist<CR>
 
 170 "TODO map <c-s> and <c-v> to open with splits.
 
 171 nnoremap <silent> <leader>bf  :<C-u>CocList buffers<CR>