dotfiles

Clean dotfiles
git clone git://git.dimitrijedobrota.com/dotfiles.git
Log | Files | Refs

clangd.vim (2944B)


      1 " Set up VIM language server using clangd
      2 
      3 if executable('clangd')
      4 	augroup lsp_clangd
      5 		autocmd!
      6 		autocmd User lsp_setup call lsp#register_server({
      7 			\ 'name': 'clangd',
      8 			\ 'cmd': {server_info->['clangd']},
      9 			\ 'whitelist': ['c', 'cpp', 'objc', 'objcpp'],
     10 			\ })
     11 		autocmd FileType c setlocal omnifunc=lsp#complete
     12 		autocmd FileType cpp setlocal omnifunc=lsp#complete
     13 		autocmd FileType objc setlocal omnifunc=lsp#complete
     14 		autocmd FileType objcpp setlocal omnifunc=lsp#complete
     15 	augroup end
     16 endif
     17 
     18 function! s:on_lsp_buffer_enabled() abort
     19   setlocal omnifunc=lsp#complete
     20   setlocal signcolumn=yes
     21   if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
     22   nmap <buffer> gd <plug>(lsp-definition)
     23   nmap <buffer> gs <plug>(lsp-document-symbol-search)
     24   nmap <buffer> gf <plug>(lsp-document-format)
     25   nmap <buffer> gD <plug>(lsp-document-diagnostics)
     26   nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
     27   nmap <buffer> gR <plug>(lsp-references)
     28   nmap <buffer> gi <plug>(lsp-implementation)
     29   nmap <buffer> gt <plug>(lsp-type-definition)
     30   nmap <buffer> <leader>rn <plug>(lsp-rename)
     31   nmap <buffer> [g <plug>(lsp-previous-diagnostic)
     32   nmap <buffer> ]g <plug>(lsp-next-diagnostic)
     33   nmap <buffer> K <plug>(lsp-hover)
     34   nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
     35   nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
     36 
     37   let g:lsp_format_sync_timeout = 1000
     38   autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
     39 
     40   " refer to doc to add more commands
     41 endfunction
     42 
     43 augroup lsp_install
     44   au!
     45   " call s:on_lsp_buffer_enabled only for languages that has the server registered.
     46   autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
     47 augroup END
     48 
     49 " set foldmethod=expr
     50 "   \ foldexpr=lsp#ui#vim#folding#foldexpr()
     51 "   \ foldtext=lsp#ui#vim#folding#foldtext()
     52 
     53 " Key bindings for vim-lsp.
     54 nn <silent> <M-d> :LspDefinition<cr>
     55 nn <silent> <M-r> :LspReferences<cr>
     56 nn <f2> :LspRename<cr>
     57 nn <silent> <M-a> :LspWorkspaceSymbol<cr>
     58 nn <silent> <M-l> :LspDocumentSymbol<cr>
     59 
     60 highlight lspReference ctermfg=red guifg=red ctermbg=NONE guibg=green
     61 
     62 autocmd User asyncomplete_setup call asyncomplete#register_source(
     63       \ asyncomplete#sources#clang#get_source_options())
     64 
     65 " Key bindings for asyncomplete
     66 inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
     67 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
     68 inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"
     69 
     70 let g:asyncomplete_auto_popup = 0
     71 
     72 function! s:check_back_space() abort
     73   let col = col('.') - 1
     74   return !col || getline('.')[col - 1]  =~ '\s'
     75 endfunction
     76 
     77 inoremap <silent><expr> <TAB>
     78       \ pumvisible() ? "\<C-n>" :
     79       \ <SID>check_back_space() ? "\<TAB>" :
     80       \ asyncomplete#force_refresh()
     81 inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
     82 
     83 let g:asyncomplete_auto_completeopt = 0
     84 set completeopt=menuone,noinsert,noselect,preview
     85 autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif