diff --git a/_Sidebar.md b/_Sidebar.md index a5615fe..acd3e35 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -6,6 +6,7 @@ - [[FAQ]] * Editor configuration - [[Emacs]] + - [[coc.nvim]] - [[LanguageClient-neovim]] - [[vim-lsp]] - [[Visual Studio Code]] diff --git a/coc.nvim.md b/coc.nvim.md new file mode 100644 index 0000000..70f12de --- /dev/null +++ b/coc.nvim.md @@ -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 \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 (coc-definition) +nmap (coc-references) +nn K :call CocActionAsync('doHover') +``` + +### `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 :call CocLocations('ccls','$ccls/navigate',{'direction':'D'}) +nn :call CocLocations('ccls','$ccls/navigate',{'direction':'L'}) +nn :call CocLocations('ccls','$ccls/navigate',{'direction':'R'}) +nn :call CocLocations('ccls','$ccls/navigate',{'direction':'U'}) +``` + +### Cross reference extensions + +```vim +" bases +nn xb :call CocLocations('ccls','$ccls/inheritance') +" bases of up to 3 levels +nn xb :call CocLocations('ccls','$ccls/inheritance',{'levels':3}) +" derived +nn xd :call CocLocations('ccls','$ccls/inheritance',{'derived':v:true}) +" derived of up to 3 levels +nn xD :call CocLocations('ccls','$ccls/inheritance',{'derived':v:true,'levels':3}) + +" caller +nn xc :call CocLocations('ccls','$ccls/call') +" callee +nn xC :call CocLocations('ccls','$ccls/call',{'callee':v:true}) + +" $ccls/member +" member variables / variables in a namespace +nn xm :call CocLocations('ccls','$ccls/member') +" member functions / functions in a namespace +nn xf :call CocLocations('ccls','$ccls/member',{'kind':3}) +" nested classes / types in a namespace +nn xs :call CocLocations('ccls','$ccls/member',{'kind':2}) + +nmap xt (coc-type-definition) +nn xv :call CocLocations('ccls','$ccls/vars') +nn xV :call CocLocations('ccls','$ccls/vars',{'kind':1}) + +nn xx x +```