Open gunslingerfry opened 6 years ago
Does your g:clang_auto_user_options
include compile_commands.json
as per documentation?
It was not. let g:clang_auto_user_options='compile_commands.json, path'
however, makes no difference.
The rest of my configuration:
let g:clang_library_path='/usr/lib/llvm-3.8/lib/libclang.so.1'
let g:clang_complete_auto=1
let g:clang_user_options='-std=gnu++14 -DOS_LINUX'
let g:clang_hl_errors=1
let g:clang_use_library=1
let g:clang_compilation_database=GetCompileDatabase()
let g:clang_complete_copen=1
let g:clang_close_preview=1
set completeopt=longest,menuone
function! GetCompileDatabase()
let l:curPathVar = '%:p'
let l:curPath = expand(l:curPathVar)
let l:allPaths = l:curPath
while l:curPath !=# '/'
let l:allPaths .= ',' . l:curPath
let l:curPathVar .= ':h'
let l:curPath = expand(l:curPathVar)
endwhile
return fnamemodify(globpath(l:allPaths, 'compile_commands.json'), ':h')
endfunction
Function just gets the path of the compile_commands.json file. It's at the root of the project but I was getting errors when I opened source files in subdirectories.
I've never tried using compilation database, maybe see #165, there was some discussion about absolute vs. relative paths.
FWIW, I don't know if the compile database support is in the clang_complete plugin or the clang library, but I gave up on this. I just switched to the .clang_complete file. It's simple enough as long as you are writing the code and giving paths relative to the main include directory i.e.
#include "mylib/myheader.h"
then my .clang_complete file becomes
-Iinclude
-DOS_LINUX
--std=c++14
which is plenty simple.
An example of my compile_commands.json file generated by using cmake/clang
clang_complete ignores the -std=gnu++14 and the -DOS_LINUX and generates errors because of them. Setting
g:clang_user_options='-std=gnu++14 -DOS_LINUX'
in my .vimrc fixes the issue.