diff options
author | w0rp <devw0rp@gmail.com> | 2017-05-02 21:18:17 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-05-02 21:18:17 +0100 |
commit | eb8bd26776fbdc57f0162d729260c4847645e145 (patch) | |
tree | 04fba5687126d64ff8cdc68f8a195ba7ee55f0b0 /ale_linters/c | |
parent | 36314aeaf2c1c5e272d7f3e5d696b5fc348081fd (diff) | |
download | ale-eb8bd26776fbdc57f0162d729260c4847645e145.zip |
#392 - Detect and use compile_commands.json for cppcheck
Diffstat (limited to 'ale_linters/c')
-rw-r--r-- | ale_linters/c/cppcheck.vim | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ale_linters/c/cppcheck.vim b/ale_linters/c/cppcheck.vim index 7da5b3ab..90805914 100644 --- a/ale_linters/c/cppcheck.vim +++ b/ale_linters/c/cppcheck.vim @@ -5,7 +5,22 @@ let g:ale_c_cppcheck_options = get(g:, 'ale_c_cppcheck_options', '--enable=style') function! ale_linters#c#cppcheck#GetCommand(buffer) abort - return 'cppcheck -q --language=c ' + " Search upwards from the file for compile_commands.json. + " + " If we find it, we'll `cd` to where the compile_commands.json file is, + " then use the file to set up import paths, etc. + let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + + let l:cd_command = !empty(l:compile_commmands_path) + \ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h')) + \ : '' + let l:compile_commands_option = !empty(l:compile_commmands_path) + \ ? '--project=compile_commands.json ' + \ : '' + + return l:cd_command + \ . 'cppcheck -q --language=c ' + \ . l:compile_commands_option \ . ale#Var(a:buffer, 'c_cppcheck_options') \ . ' %t' endfunction |