mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-07 18:31:04 +08:00
Fix #1279 - Run cppcheck differently when modified
cppcheck is now run without the --project option and from the buffer's directory instead when the buffer has been modified. Saving the buffer will get results by linting the project instead.
This commit is contained in:
@@ -1,5 +1,46 @@
|
||||
" Description: Handle errors for cppcheck.
|
||||
|
||||
function! ale#handlers#cppcheck#GetCdCommand(buffer) abort
|
||||
let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
|
||||
let l:cd_command = !empty(l:dir) ? ale#path#CdString(l:dir) : ''
|
||||
|
||||
return l:cd_command
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#cppcheck#GetBufferPathIncludeOptions(buffer) abort
|
||||
let l:buffer_path_include = ''
|
||||
|
||||
" Get path to this buffer so we can include it into cppcheck with -I
|
||||
" This could be expanded to get more -I directives from the compile
|
||||
" command in compile_commands.json, if it's found.
|
||||
let l:buffer_path = fnamemodify(bufname(a:buffer), ':p:h')
|
||||
let l:buffer_path_include = ' -I' . ale#Escape(l:buffer_path)
|
||||
|
||||
return l:buffer_path_include
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#cppcheck#GetCompileCommandsOptions(buffer) abort
|
||||
" If the current buffer is modified, using compile_commands.json does no
|
||||
" good, so include the file's directory instead. It's not quite as good as
|
||||
" using --project, but is at least equivalent to running cppcheck on this
|
||||
" file manually from the file's directory.
|
||||
let l:modified = getbufvar(a:buffer, '&modified')
|
||||
|
||||
if l:modified
|
||||
return ''
|
||||
endif
|
||||
|
||||
" 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:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
|
||||
|
||||
return !empty(l:json_path)
|
||||
\ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
|
||||
\ : ''
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#cppcheck#HandleCppCheckFormat(buffer, lines) abort
|
||||
" Look for lines like the following.
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user