diff --git a/doc/clang_complete.txt b/doc/clang_complete.txt index d6a6e765..b1f435de 100644 --- a/doc/clang_complete.txt +++ b/doc/clang_complete.txt @@ -194,6 +194,30 @@ time before doing completion. Default: "path, .clang_complete" + *clang_complete-compilation_database_search_path* + *g:clang_compilation_database_search_path* +By default, when the compile_commands.json option is specified for +|g:clang_user_options| the upwards search is for that filename. To change the +name of this file or to search different subdirectories, you may set +|g:clang_compilation_database_search_path|. + +For example, specifying build/compile_commands.json will allow out of source +builds with cmake. + +Default: "compile_commands.json" + + *clang_complete-clang_complete_search_path* + *g:clang_complete_search_path* +By default, when the .clang_complete option is specified for +|g:clang_user_options| the upwards search is for that filename. To change the +name of this file or to search different subdirectories, you may set +|g:clang_complete_search_path|. + +For example, specifying build/.clang_complete will allow out of source +builds with cmake. + +Default: ".clang_complete" + *clang_complete-compilation_database* *g:clang_compilation_database* By default, clang_complete will search upwards from where it was started to diff --git a/plugin/clang_complete.vim b/plugin/clang_complete.vim index a1ce0e79..2b2deadf 100644 --- a/plugin/clang_complete.vim +++ b/plugin/clang_complete.vim @@ -17,6 +17,10 @@ let b:my_changedtick = 0 " not during a function call. let s:plugin_path = escape(expand(':p:h'), '\') +" Default filenames +let s:default_compilation_database_filename = 'compile_commands.json' +let s:default_clang_complete_filename = '.clang_complete' + function! s:ClangCompleteInit() let l:bufname = bufname("%") if l:bufname == '' @@ -58,7 +62,7 @@ function! s:ClangCompleteInit() endif if !exists('g:clang_snippets_engine') - let g:clang_snippets_engine = 'clang_complete' + let g:clang_snippets_engine = s:default_clang_complete_filename endif if !exists('g:clang_user_options') @@ -75,6 +79,14 @@ function! s:ClangCompleteInit() let g:clang_trailing_placeholder = 0 endif + if !exists("g:clang_compilation_database_search_path") + let g:clang_compilation_database_search_path = s:default_compilation_database_filename + endif + + if !exists('g:clang_complete_search_path') + let g:clang_complete_search_path = s:default_clang_complete_filename + endif + if !exists('g:clang_compilation_database') let g:clang_compilation_database = '' endif @@ -100,7 +112,7 @@ function! s:ClangCompleteInit() endif if !exists('g:clang_auto_user_options') - let g:clang_auto_user_options = 'path, .clang_complete' + let g:clang_auto_user_options = 'path, ' . s:default_clang_complete_filename endif if !exists('g:clang_jumpto_declaration_key') @@ -187,10 +199,10 @@ function! LoadUserOptions() endif if l:source == 'path' call s:parsePathOption() - elseif l:source == 'compile_commands.json' - call s:findCompilationDatase(l:source) - elseif l:source == '.clang_complete' - call s:parseConfig() + elseif l:source == s:default_compilation_database_filename + call s:findCompilationDatase(g:clang_compilation_database_search_path) + elseif l:source == s:default_clang_complete_filename + call s:parseConfig(g:clang_complete_search_path) else let l:getopts = 'getopts#' . l:source . '#getopts' silent call eval(l:getopts . '()') @@ -198,8 +210,8 @@ function! LoadUserOptions() endfor endfunction -function! s:parseConfig() - let l:local_conf = findfile('.clang_complete', getcwd() . ',.;') +function! s:parseConfig(ccpath) + let l:local_conf = findfile(a:ccpath, getcwd() . ',.;') if l:local_conf == '' || !filereadable(l:local_conf) return endif