Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to specify paths for options files #347

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/clang_complete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions plugin/clang_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ let b:my_changedtick = 0
" not during a function call.
let s:plugin_path = escape(expand('<sfile>: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 == ''
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -187,19 +199,19 @@ 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 . '()')
endif
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
Expand Down