summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-03-11 16:47:32 +0000
committerw0rp <devw0rp@gmail.com>2017-03-11 16:48:49 +0000
commitd58a18b8edd4e42be0456454933ac266c230d97e (patch)
tree389c84eab5a9ce33c09073f1f488d55f7198a666
parentc2ceb9e085c8dd849dee57bdd91b2500fa7b528f (diff)
downloadale-d58a18b8edd4e42be0456454933ac266c230d97e.zip
#277 #318 Support all same-directory includes for gcc and clang
-rw-r--r--ale_linters/c/clang.vim12
-rw-r--r--ale_linters/c/gcc.vim6
-rw-r--r--ale_linters/cpp/clang.vim12
-rw-r--r--ale_linters/cpp/gcc.vim6
4 files changed, 26 insertions, 10 deletions
diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim
index 205dd922..603e2b75 100644
--- a/ale_linters/c/clang.vim
+++ b/ale_linters/c/clang.vim
@@ -9,12 +9,18 @@ if !exists('g:ale_c_clang_options')
let g:ale_c_clang_options = '-std=c11 -Wall'
endif
+function! ale_linters#c#clang#GetCommand(buffer) abort
+ " -iquote with the directory the file is in makes #include work for
+ " headers in the same directory.
+ return 'clang -S -x c -fsyntax-only '
+ \ . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+ \ . ' ' . g:ale_c_clang_options . ' -'
+endfunction
+
call ale#linter#Define('c', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable': 'clang',
-\ 'command': 'clang -S -x c -fsyntax-only '
-\ . g:ale_c_clang_options
-\ . ' -',
+\ 'command_callback': 'ale_linters#c#clang#GetCommand',
\ 'callback': 'ale#handlers#HandleGCCFormat',
\})
diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim
index 594c5c83..a487909c 100644
--- a/ale_linters/c/gcc.vim
+++ b/ale_linters/c/gcc.vim
@@ -10,9 +10,11 @@ if !exists('g:ale_c_gcc_options')
endif
function! ale_linters#c#gcc#GetCommand(buffer) abort
+ " -iquote with the directory the file is in makes #include work for
+ " headers in the same directory.
return 'gcc -S -x c -fsyntax-only '
- \ . g:ale_c_gcc_options . ' -'
-
+ \ . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+ \ . ' ' . g:ale_c_gcc_options . ' -'
endfunction
call ale#linter#Define('c', {
diff --git a/ale_linters/cpp/clang.vim b/ale_linters/cpp/clang.vim
index 7cd86968..9915ac3a 100644
--- a/ale_linters/cpp/clang.vim
+++ b/ale_linters/cpp/clang.vim
@@ -6,12 +6,18 @@ if !exists('g:ale_cpp_clang_options')
let g:ale_cpp_clang_options = '-std=c++14 -Wall'
endif
+function! ale_linters#cpp#clang#GetCommand(buffer) abort
+ " -iquote with the directory the file is in makes #include work for
+ " headers in the same directory.
+ return 'clang++ -S -x c++ -fsyntax-only '
+ \ . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+ \ . ' ' . g:ale_cpp_clang_options . ' -'
+endfunction
+
call ale#linter#Define('cpp', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable': 'clang++',
-\ 'command': 'clang++ -S -x c++ -fsyntax-only '
-\ . g:ale_cpp_clang_options
-\ . ' -',
+\ 'command_callback': 'ale_linters#cpp#clang#GetCommand',
\ 'callback': 'ale#handlers#HandleGCCFormat',
\})
diff --git a/ale_linters/cpp/gcc.vim b/ale_linters/cpp/gcc.vim
index 200a25c1..ad1b93b7 100644
--- a/ale_linters/cpp/gcc.vim
+++ b/ale_linters/cpp/gcc.vim
@@ -16,9 +16,11 @@ if !exists('g:ale_cpp_gcc_options')
endif
function! ale_linters#cpp#gcc#GetCommand(buffer) abort
+ " -iquote with the directory the file is in makes #include work for
+ " headers in the same directory.
return 'gcc -S -x c++ -fsyntax-only '
- \ . g:ale_cpp_gcc_options . ' -'
-
+ \ . '-iquote ' . fnameescape(fnamemodify(bufname(a:buffer), ':p:h'))
+ \ . ' ' . g:ale_cpp_gcc_options . ' -'
endfunction
call ale#linter#Define('cpp', {