summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMo Zhonghua <mozhonghua@yeah.net>2019-09-20 03:20:37 +0800
committerw0rp <w0rp@users.noreply.github.com>2019-09-19 20:20:37 +0100
commitb8949aaac33e152b195d3adf11ddbe863c0feef1 (patch)
tree1971ca2ae3ed1a47a38d60599642fbc11ab9cea6
parentdc42c0f948d378557894fa09160d231b795dfca4 (diff)
downloadale-b8949aaac33e152b195d3adf11ddbe863c0feef1.zip
`arguments` needs to be handled for `compile_commands.json` in addition to `command` (#2123)
* c linter: compatible with compile_commands.json without command field
-rw-r--r--autoload/ale/c.vim18
1 files changed, 13 insertions, 5 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index 5540ec14..9b428700 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -265,6 +265,16 @@ function! s:GetLookupFromCompileCommandsFile(compile_commands_file) abort
return l:empty
endfunction
+function! ale#c#GetCompileCommand(json_item) abort
+ if has_key(a:json_item, 'command')
+ return a:json_item.command
+ elseif has_key(a:json_item, 'arguments')
+ return join(a:json_item.arguments, ' ')
+ endif
+
+ return ''
+endfunction
+
function! ale#c#ParseCompileCommandsFlags(buffer, file_lookup, dir_lookup) abort
" Search for an exact file match first.
let l:basename = tolower(expand('#' . a:buffer . ':t'))
@@ -287,15 +297,14 @@ function! ale#c#ParseCompileCommandsFlags(buffer, file_lookup, dir_lookup) abort
for l:item in l:file_list
" Load the flags for this file, or for a source file matching the
" header file.
- if has_key(l:item, 'command')
- \&& (
+ if (
\ bufnr(l:item.file) is a:buffer
\ || (
\ !empty(l:source_file)
\ && l:item.file[-len(l:source_file):] is? l:source_file
\ )
\)
- return ale#c#ParseCFlags(l:item.directory, l:item.command)
+ return ale#c#ParseCFlags(l:item.directory, ale#c#GetCompileCommand(l:item))
endif
endfor
@@ -307,8 +316,7 @@ function! ale#c#ParseCompileCommandsFlags(buffer, file_lookup, dir_lookup) abort
for l:item in l:dir_list
if ale#path#Simplify(fnamemodify(l:item.file, ':h')) is? l:dir
- \&& has_key(l:item, 'command')
- return ale#c#ParseCFlags(l:item.directory, l:item.command)
+ return ale#c#ParseCFlags(l:item.directory, ale#c#GetCompileCommand(l:item))
endif
endfor