Skip to content

LanguageClient neovim

Fangrui Song edited this page Sep 1, 2018 · 17 revisions
  1. See Getting started to build the ccls executable
  2. Install LanguageClient-neovim You may use the plugin manager vim-plug

/home/YOUR_USERNAME/.config/nvim/init.vim

" LanguageClient-neovim 
call plug#begin('~/.local/share/nvim/plugged')
Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }

" Multi-entry selection UI. FZF
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

call plug#end()

bash

nvim +PlugInstall +UpdateRemotePlugins +qa

~/.config/nvim/settings.json

{
        "initializationOptions": {
                "cacheDirectory": "/tmp/ccls"
        }
}

~/.config/nvim/init.vim

let g:LanguageClient_serverCommands = {
    \ 'cpp': ['ccls', '--log-file=/tmp/cq.log'],
    \ 'c': ['ccls', '--log-file=/tmp/cq.log'],
    \ } 

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 <silent> gh :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> gr :call LanguageClient_textDocument_references()<CR>
nnoremap <silent> gs :call LanguageClient_textDocument_documentSymbol()<CR>
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>

In your Project Directory NEED compile_commands.json

compile_commands.json

bear make #If you like Makefile

or

bear gcc x.c -o x

or any other

Custom cross references

" one-level base
nn <silent> xB :call LanguageClient#findLocations({'method':'$ccls/base'})<cr>
" bases of up to 3 levels
nn <silent> xb :call LanguageClient#findLocations({'method':'$ccls/inheritanceHierarchy','flat':v:true,'levels':3,'derived':v:false})<cr>
" derived of up to 3 levels
nn <silent> xd :call LanguageClient#findLocations({'method':'$ccls/inheritanceHierarchy','flat':v:true,'levels':3,'derived':v:true})<cr>
nn <silent> xe :call LanguageClient#findLocations({'method':'$ccls/callers'})<cr>
nn <silent> xm :call LanguageClient#findLocations({'method':'$ccls/memberHierarchy','flat':v:true})<cr>
nn <silent> xt :call LanguageClient#textDocument_typeDefinition()<cr>
nn <silent> xv :call LanguageClient#findLocations({'method':'$ccls/vars'})<cr>
nn <silent> xV :call LanguageClient#findLocations({'method':'$ccls/vars','kind':1})<cr>
nn xx x

$ccls/inheritanceHierarchy flat:t derived:false: base classes/overridden methods/specialized from

$ccls/inheritanceHierarchy flat:t derived:false

$ccls/inheritanceHierarchy flat:t derived:true

$ccls/inheritanceHierarchy flat:t derived:true

$ccls/callers: callers of a function

$ccls/callers

The more general $ccls/callHierarchy has not been implemented by a Vim plugin.

$ccls/vars: instances of a type

$ccls/vars

$ccls/memberHierarchy flat:t: fields of a struct/class/union/...

$ccls/memberHierarchy flat:t

Clone this wiki locally