diff options
author | roel0 <roel.postelmans@altran.com> | 2018-03-27 10:18:24 +0200 |
---|---|---|
committer | roel0 <roel.postelmans@altran.com> | 2018-03-27 10:18:24 +0200 |
commit | dfb3e194d7a05b747c77d312a72e5149595bbcef (patch) | |
tree | c98cf493af29ceabaaa2e63ab3a014c30e609ca6 /autoload | |
parent | cf62ef7b070c08bc6858aa88f0ff45be56b7c9b7 (diff) | |
download | ale-dfb3e194d7a05b747c77d312a72e5149595bbcef.zip |
Extended unit tests + simplified parsing algoritme #1167
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/c.vim | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index 54e553b9..5ab10f00 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -24,44 +24,30 @@ function! ale#c#FindProjectRoot(buffer) abort endfunction function! ale#c#ParseCFlagsToList(path_prefix, cflags) abort - let l:previous_option = '' - let l:shell_option = 0 - let l:macro_option = 0 let l:cflags_list = [] + let l:previous_options = [] for l:option in a:cflags - - " Check if cflag contained spaces - if l:shell_option || stridx(l:option, '=`') >= 0 - " Cflag contained shell command with spaces (ex. -D='date +%s') - let l:shell_option = 1 - let l:previous_option .= l:option - if l:option[-1: -1] isnot? '`' - let l:previous_option .= ' ' - continue - endif - let l:shell_option = 0 - elseif l:macro_option || stridx(l:option, '$((') > 0 - " Cflag contained macro with spaces (ex -Da=$(( 4 * 20 ))) - let l:macro_option = 1 - let l:previous_option .= l:option - if stridx(l:option, '))') < 0 - let l:previous_option .= ' ' - continue - endif - let l:macro_option = 0 + call add(l:previous_options, l:option) + " Check if cflag contained a '-' and should not have been splitted + let l:option_list = split(l:option, '\zs') + if l:option_list[-1] isnot# ' ' + continue endif - if l:previous_option isnot? '' - let l:option = l:previous_option - let l:previous_option = '' - endif + let l:option = join(l:previous_options, '-') + let l:previous_options = [] + + let l:option = '-' . substitute(l:option, '^\s*\(.\{-}\)\s*$', '\1', '') " Fix relative paths if needed - if stridx(l:option, '-I') >= 0 - if stridx(l:option, '-I' . s:sep) < 0 - let l:option = '-I' . a:path_prefix . s:sep . l:option[2:] - endif + if stridx(l:option, '-I') >= 0 && + \ stridx(l:option, '-I' . s:sep) < 0 + let l:rel_path = join(split(l:option, '\zs')[2:], '') + let l:rel_path = substitute(l:rel_path, '"', '', 'g') + let l:rel_path = substitute(l:rel_path, '''', '', 'g') + let l:option = ale#Escape('-I' . a:path_prefix . + \ s:sep . l:rel_path) endif " Parse the cflag @@ -81,11 +67,11 @@ function! ale#c#ParseCFlags(buffer, stdout_make) abort return [] endif - let l:buffer_filename = expand('#' . a:buffer . '...') - - for l:cflags in split(a:stdout_make, '\n') - if stridx(l:cflags, l:buffer_filename) - let l:cflags = split(l:cflags) + let l:buffer_filename = expand('#' . a:buffer . ':t') + let l:cflags = [] + for l:lines in split(a:stdout_make, '\\n') + if stridx(l:lines, l:buffer_filename) >= 0 + let l:cflags = split(l:lines, '-') break endif endfor |