From e29cc5696d63e2426c9cc5a7c5990b6d9945f114 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 24 Nov 2018 10:56:48 -0800 Subject: [PATCH] Add coc.nvim --- _Sidebar.md | 1 + coc.nvim.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 coc.nvim.md 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 +```