diff --git a/LanguageClient-neovim.md b/LanguageClient-neovim.md index 51cd8ca..19c4e3f 100644 --- a/LanguageClient-neovim.md +++ b/LanguageClient-neovim.md @@ -2,28 +2,13 @@ 2. Install [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) You may use the plugin manager [vim-plug](https://github.com/junegunn/vim-plug#unix-1) -### /home/YOUR_USERNAME/.config/nvim/init.vim -```vim -" LanguageClient-neovim -call plug#begin('~/.local/share/nvim/plugged') -Plug 'autozimu/LanguageClient-neovim', { - \ 'branch': 'next', - \ 'do': 'bash install.sh', - \ } +LanguageClient-neovim -" Multi-entry selection UI. FZF -Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } -Plug 'junegunn/fzf.vim' - -call plug#end() -``` - -### bash ```bash nvim +PlugInstall +UpdateRemotePlugins +qa ``` -`~/.config/nvim/settings.json` +`~/.config/nvim/settings.json` (optional, by default it creates cache directory `.ccls-cache` in the project root) ```json { "initializationOptions": { @@ -35,40 +20,47 @@ nvim +PlugInstall +UpdateRemotePlugins +qa `~/.config/nvim/init.vim` ```vim let g:LanguageClient_serverCommands = { - \ 'cpp': ['ccls', '--log-file=/tmp/cq.log'], - \ 'c': ['ccls', '--log-file=/tmp/cq.log'], - \ } + \ 'cpp': ['ccls', '--log-file=/tmp/cc.log'], + \ 'c': ['ccls', '--log-file=/tmp/cc.log'], + \ } -let g:LanguageClient_loadSettings = 1 " Use an absolute configuration path if you want system-wide settings +let g:LanguageClient_loadSettings = 1 " Use an absolute configuration path if you want system-wide settings let g:LanguageClient_settingsPath = '/home/YOUR_USERNAME/.config/nvim/settings.json' -set completefunc=LanguageClient#complete -set formatexpr=LanguageClient_textDocument_rangeFormatting() - -nnoremap gh :call LanguageClient_textDocument_hover() -nnoremap gd :call LanguageClient_textDocument_definition() -nnoremap gr :call LanguageClient_textDocument_references() -nnoremap gs :call LanguageClient_textDocument_documentSymbol() -nnoremap :call LanguageClient_textDocument_rename() ``` -### In your Project Directory NEED compile_commands.json +Make sure you have `.ccls` or [[compile_commands.json]] in your project root. Open a file in the project, run `:LanguageClientStart`. -[[compile_commands.json]] +These features will work out-of-the-box. -```bash -bear make #If you like Makefile +```vim +nn :call LanguageClient#textDocument_definition() +nn :call LanguageClient#textDocument_references({'includeDeclaration': v:false}) +nn K :call LanguageClient#textDocument_hover() ``` -or +### `textDocument/documentHighlight` -```bash -bear gcc x.c -o x +```vim +augroup LanguageClient_config + au! + au BufEnter * let b:Plugin_LanguageClient_started = 0 + au User LanguageClientStarted setl signcolumn=yes + au User LanguageClientStarted let b:Plugin_LanguageClient_started = 1 + au User LanguageClientStopped setl signcolumn=auto + au User LanguageClientStopped let b:Plugin_LanguageClient_stopped = 0 + au CursorMoved * if b:Plugin_LanguageClient_started | sil call LanguageClient#textDocument_documentHighlight() | endif +augroup END ``` -or any other - ### `$ccls/navigate` +Semantic navigation. Roughly, + +"D" => first child declaration +"L" => previous declaration +"R" => next declaration +"U" => parent declaration + ```vim nn xh :call LanguageClient#findLocations({'method':'$ccls/navigate','direction':'L'}) nn xj :call LanguageClient#findLocations({'method':'$ccls/navigate','direction':'D'}) @@ -76,6 +68,8 @@ nn xk :call LanguageClient#findLocations({'method':'$ccls/navigate','di nn xl :call LanguageClient#findLocations({'method':'$ccls/navigate','direction':'R'}) ``` +![](https://ptpb.pw/89Y2.gif) + ### Custom cross references ```vim