diff options
author | w0rp <w0rp@users.noreply.github.com> | 2018-11-17 20:28:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-17 20:28:11 +0000 |
commit | f538bb440a8d9e5f607fe7a8d54f7862537586d9 (patch) | |
tree | 1eb888a8debc1206e3c13749711597f2f9e14341 | |
parent | 531868f759404e11d1f34f72e19dcd6112a88567 (diff) | |
parent | 1b3fa9828c79a6ca53561945348832de66cbab7b (diff) | |
download | ale-f538bb440a8d9e5f607fe7a8d54f7862537586d9.zip |
Merge pull request #1907 from guill/compile_commands_fix
Fix bug where last C compile flag was ignored
-rw-r--r-- | autoload/ale/c.vim | 11 | ||||
-rw-r--r-- | test/test_c_flag_parsing.vader | 16 |
2 files changed, 24 insertions, 3 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index ce59ae31..ce5105b6 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -50,12 +50,17 @@ function! ale#c#ParseCFlags(path_prefix, cflag_line) abort let l:cflags_list = [] let l:previous_options = [] - for l:option in split(a:cflag_line, '-') + let l:split_lines = split(a:cflag_line, '-') + let l:option_index = 0 + + while l:option_index < len(l:split_lines) + let l:option = l:split_lines[l:option_index] + let l:option_index = l:option_index + 1 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 len(l:option_list) > 0 && l:option_list[-1] isnot# ' ' + if len(l:option_list) > 0 && l:option_list[-1] isnot# ' ' && l:option_index < len(l:split_lines) continue endif @@ -81,7 +86,7 @@ function! ale#c#ParseCFlags(path_prefix, cflag_line) abort call add(l:cflags_list, l:option) endif endif - endfor + endwhile return join(l:cflags_list, ' ') endfunction diff --git a/test/test_c_flag_parsing.vader b/test/test_c_flag_parsing.vader index f7bfaa04..8a9b7189 100644 --- a/test/test_c_flag_parsing.vader +++ b/test/test_c_flag_parsing.vader @@ -141,6 +141,22 @@ Execute(ParseCFlags should handle -D with minuses): \ . ' -DTEST=`date +%s` -c file.c' \ ) +Execute(ParseCFlags should handle flags at the end of the line): + AssertEqual + \ '-Dgoal=9' + \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' -Dmacro-with-dash' + \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) + \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')), + \ ale#c#ParseCFlags( + \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ . '-Dmacro-with-dash ' + \ . '-I''dir with spaces''' . ' -Idir-with-dash' + \ . ' -I'. ale#path#Simplify('kernel/include') + \ ) + Execute(FlagsFromCompileCommands should tolerate empty values): AssertEqual '', ale#c#FlagsFromCompileCommands(bufnr(''), '') |