Skip to content

Commit 5e48e97

Browse files
Konfektchrisbra
authored andcommitted
runtime(compiler): check for compile_commands in build dirs for cppcheck
closes: #15889 Signed-off-by: Konfekt <Konfekt@users.noreply.github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 8fc2a09 commit 5e48e97

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

runtime/compiler/cppcheck.vim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" vim compiler file
22
" Compiler: cppcheck (C++ static checker)
33
" Maintainer: Vincent B. (twinside@free.fr)
4-
" Last Change: 2024 Oct 4 by @Konfekt
4+
" Last Change: 2024 oct 17 by @Konfekt
55

66
if exists("cppcheck")
77
finish
@@ -11,6 +11,8 @@ let current_compiler = "cppcheck"
1111
let s:cpo_save = &cpo
1212
set cpo-=C
1313

14+
let s:slash = has('win32')? '\' : '/'
15+
1416
if !exists('g:c_cppcheck_params')
1517
let g:c_cppcheck_params = '--verbose --force --inline-suppr'
1618
\ ..' '..'--enable=warning,style,performance,portability,information,missingInclude'
@@ -20,11 +22,11 @@ endif
2022

2123
let &l:makeprg = 'cppcheck --quiet'
2224
\ ..' --template="{file}:{line}:{column}: {severity}: [{id}] {message} {callstack}"'
23-
\ ..' '..get(b:, 'c_cppcheck_params',
24-
\ g:c_cppcheck_params..' '..(&filetype ==# 'cpp' ? ' --language=c++' : ''))
25+
\ ..' '..get(b:, 'c_cppcheck_params', get(g:, 'c_cppcheck_params', (&filetype ==# 'cpp' ? ' --language=c++' : '')))
2526
\ ..' '..get(b:, 'c_cppcheck_includes', get(g:, 'c_cppcheck_includes',
2627
\ (filereadable('compile_commands.json') ? '--project=compile_commands.json' :
27-
\ (empty(&path) ? '' : '-I')..join(map(filter(split(&path, ','), 'isdirectory(v:val)'),'shellescape(v:val)'), ' -I'))))
28+
\ (!empty(glob('*'..s:slash..'compile_commands.json', 1, 1)) ? '--project='..glob('*'..s:slash..'compile_commands.json', 1, 1)[0] :
29+
\ (empty(&path) ? '' : '-I')..join(map(filter(split(&path, ','), 'isdirectory(v:val)'),'shellescape(v:val)'), ' -I')))))
2830
silent CompilerSet makeprg
2931

3032
CompilerSet errorformat=

0 commit comments

Comments
 (0)