Add coc.nvim

Fangrui Song 2018-11-24 10:56:48 -08:00
parent 05f2495254
commit e29cc5696d
2 changed files with 91 additions and 0 deletions

@ -6,6 +6,7 @@
- [[FAQ]]
* Editor configuration
- [[Emacs]]
- [[coc.nvim]]
- [[LanguageClient-neovim]]
- [[vim-lsp]]
- [[Visual Studio Code]]

90
coc.nvim.md Normal file

@ -0,0 +1,90 @@
1. See [[Getting started]] to build the `ccls` executable
2. Install [coc.nvim](https://github.com/neoclide/coc.nvim)
`~/.config/nvim/coc-settings.json`
```json
{
"languageserver": {
"ccls": {
"command": "ccls",
"filetypes": ["c", "cpp", "cuda", "objc", "objcpp"],
"initializationOptions": {}
}
}
}
```
First example:
```zsh
cd /tmp; mkdir c; cd c
git init # let coc.nvim know this is a project
echo '#include <stddef.h>\nint main() {}' > a.cc
nvim a.cc
```
For a larger project, you'll need [[.ccls|Getting-started#ccls]] or [[compile_commands.json]] in your project root.
These features will work out-of-the-box. Find more on coc.nvim's README.
```vim
nmap <silent> <M-j> <Plug>(coc-definition)
nmap <silent> <C-,> <Plug>(coc-references)
nn <silent> K :call CocActionAsync('doHover')<cr>
```
### `textDocument/documentHighlight`
```vim
set updatetime=300
au CursorHold * sil call CocActionAsync('highlight')
au CursorHoldI * sil call CocActionAsync('showSignatureHelp')
```
### `$ccls/navigate`
Semantic navigation. Roughly,
"D" => first child declaration
"L" => previous declaration
"R" => next declaration
"U" => parent declaration
```vim
nn <silent><buffer> <C-l> :call CocLocations('ccls','$ccls/navigate',{'direction':'D'})<cr>
nn <silent><buffer> <C-k> :call CocLocations('ccls','$ccls/navigate',{'direction':'L'})<cr>
nn <silent><buffer> <C-j> :call CocLocations('ccls','$ccls/navigate',{'direction':'R'})<cr>
nn <silent><buffer> <C-h> :call CocLocations('ccls','$ccls/navigate',{'direction':'U'})<cr>
```
### Cross reference extensions
```vim
" bases
nn <silent> xb :call CocLocations('ccls','$ccls/inheritance')<cr>
" bases of up to 3 levels
nn <silent> xb :call CocLocations('ccls','$ccls/inheritance',{'levels':3})<cr>
" derived
nn <silent> xd :call CocLocations('ccls','$ccls/inheritance',{'derived':v:true})<cr>
" derived of up to 3 levels
nn <silent> xD :call CocLocations('ccls','$ccls/inheritance',{'derived':v:true,'levels':3})<cr>
" caller
nn <silent> xc :call CocLocations('ccls','$ccls/call')<cr>
" callee
nn <silent> xC :call CocLocations('ccls','$ccls/call',{'callee':v:true})<cr>
" $ccls/member
" member variables / variables in a namespace
nn <silent> xm :call CocLocations('ccls','$ccls/member')<cr>
" member functions / functions in a namespace
nn <silent> xf :call CocLocations('ccls','$ccls/member',{'kind':3})<cr>
" nested classes / types in a namespace
nn <silent> xs :call CocLocations('ccls','$ccls/member',{'kind':2})<cr>
nmap <silent> xt <Plug>(coc-type-definition)<cr>
nn <silent> xv :call CocLocations('ccls','$ccls/vars')<cr>
nn <silent> xV :call CocLocations('ccls','$ccls/vars',{'kind':1})<cr>
nn xx x
```