summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorroel0 <roel.postelmans@altran.com>2018-03-20 21:49:31 +0100
committerroel0 <roel.postelmans@altran.com>2018-03-20 21:49:31 +0100
commit18d0aeb1a0cca2b749c3d2232f853fcaddcdb56b (patch)
treea6462ea0e55dd59f12e247ce39fc35b1861895d7 /autoload
parent38953c46266706541569f6f89c19ef8af59d36f5 (diff)
downloadale-18d0aeb1a0cca2b749c3d2232f853fcaddcdb56b.zip
* Shell commands should by called async with the help of a command chain
* The makefile parser unit test should only test the cflag parser itself #1167
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/c.vim56
1 files changed, 36 insertions, 20 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index 7dc532b3..314bb9a9 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -1,6 +1,7 @@
" Author: gagbo <gagbobada@gmail.com>, w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with C-family linters.
+call ale#Set('c_parse_makefile', 0)
let s:sep = has('win32') ? '\' : '/'
function! ale#c#FindProjectRoot(buffer) abort
@@ -22,27 +23,30 @@ function! ale#c#FindProjectRoot(buffer) abort
return ''
endfunction
-function! ale#c#ParseCFlags(project_root, stdout_make) abort
- let l:cflags_list = []
- let l:cflags = split(a:stdout_make)
+function! ale#c#ParseCFlagsToList(buffer, cflags) abort
+ let l:project_root = ale#c#FindProjectRoot(a:buffer)
+ let l:previous_option = ''
let l:shell_option = 0
let l:macro_option = 0
- let l:previous_option = ''
- for l:option in l:cflags
+ let l:cflags_list = []
+
+ 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 . ' '
+ 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 . ' '
+ let l:previous_option .= l:option
if stridx(l:option, '))') < 0
+ let l:previous_option .= ' '
continue
endif
let l:macro_option = 0
@@ -54,7 +58,7 @@ function! ale#c#ParseCFlags(project_root, stdout_make) abort
" Fix relative paths if needed
if stridx(l:option, '-I') >= 0
if stridx(l:option, '-I' . s:sep) < 0
- let l:option = '-I' . a:project_root . s:sep . l:option[2:]
+ let l:option = '-I' . l:project_root . s:sep . l:option[2:]
endif
endif
" Parse the cflag
@@ -68,21 +72,33 @@ function! ale#c#ParseCFlags(project_root, stdout_make) abort
return l:cflags_list
endfunction
+function! ale#c#ParseCFlags(buffer, stdout_make) abort
+ if g:ale_c_parse_makefile
+ for l:cflags in split(a:stdout_make, '\n')
+ if stridx(l:cflags, expand('#' . a:buffer . '...'))
+ let l:cflags = split(l:cflags)
+ break
+ endif
+ endfor
+ if !empty(l:cflags)
+ return ale#c#ParseCFlagsToList(a:buffer, l:cflags)
+ endif
+ endif
+ retur []
+endfunction
+
function! ale#c#ParseMakefile(buffer) abort
- let l:project_root = ale#c#FindProjectRoot(a:buffer)
- let l:project_cflags = []
-
- if !empty(l:project_root)
- if !empty(globpath(l:project_root, 'Makefile', 0))
- let l:stdout_make = system('cd '. l:project_root . ' && make -n')
- for l:object in split(l:stdout_make, '\n')
- if stridx(l:object, expand('#' . a:buffer . '...'))
- return ale#c#ParseCFlags(l:project_root, l:object)
- endif
- endfor
+ if g:ale_c_parse_makefile
+ let l:project_root = ale#c#FindProjectRoot(a:buffer)
+ let l:project_cflags = []
+
+ if !empty(l:project_root)
+ if !empty(globpath(l:project_root, 'Makefile', 0))
+ return 'cd '. l:project_root . ' && make -n'
+ endif
endif
endif
- return []
+ return ''
endfunction
" Given a buffer number, search for a project root, and output a List