From b8949aaac33e152b195d3adf11ddbe863c0feef1 Mon Sep 17 00:00:00 2001 From: Mo Zhonghua Date: Fri, 20 Sep 2019 03:20:37 +0800 Subject: `arguments` needs to be handled for `compile_commands.json` in addition to `command` (#2123) * c linter: compatible with compile_commands.json without command field --- autoload/ale/c.vim | 18 +++++++++++++----- 1 file 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 -- cgit v1.2.3