summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorNicolas Pauss <nicolas.pauss@intersec.com>2022-10-12 00:05:37 +0200
committerGitHub <noreply@github.com>2022-10-12 07:05:37 +0900
commit951a668b1490f0b3dcdcec6b4ebf3f626c0f416f (patch)
tree48eac8f7911b6fcfc1ad47ef02f84416628ccfcd /ale_linters
parentf085227504076dff5224cbf10cb1bf83286188a9 (diff)
downloadale-951a668b1490f0b3dcdcec6b4ebf3f626c0f416f.zip
cc: fix using '-x c*-header' for header files with GCC. (#4334)
Gcc does not support `x c*-header` when using `-` as input filename, which is what ALE does. Rework the feature to only use `-x c*-header` flag when using Clang and not GCC. The feature is now also controlled with the variable `g:ale_c_cc_use_header_lang_flag` and `g:ale_cpp_cc_use_header_lang_flag`.
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/c/cc.vim15
-rw-r--r--ale_linters/cpp/cc.vim15
2 files changed, 26 insertions, 4 deletions
diff --git a/ale_linters/c/cc.vim b/ale_linters/c/cc.vim
index d0215041..35125f2f 100644
--- a/ale_linters/c/cc.vim
+++ b/ale_linters/c/cc.vim
@@ -3,6 +3,7 @@
call ale#Set('c_cc_executable', '<auto>')
call ale#Set('c_cc_options', '-std=c11 -Wall')
+call ale#Set('c_cc_use_header_lang_flag', -1)
call ale#Set('c_cc_header_exts', ['h'])
function! ale_linters#c#cc#GetExecutable(buffer) abort
@@ -23,8 +24,6 @@ endfunction
function! ale_linters#c#cc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'c_cc_options')
- let l:header_exts = ale#Var(a:buffer, 'c_cc_header_exts')
- let l:lang_flag = ale#c#GetLanguageFlag(a:buffer, l:header_exts, 'c')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
@@ -34,6 +33,18 @@ function! ale_linters#c#cc#GetCommand(buffer, output) abort
\ 'g')
endif
+ " Select the correct language flag depending on the executable, options
+ " and file extension
+ let l:executable = ale_linters#c#cc#GetExecutable(a:buffer)
+ let l:use_header_lang_flag = ale#Var(a:buffer, 'c_cc_use_header_lang_flag')
+ let l:header_exts = ale#Var(a:buffer, 'c_cc_header_exts')
+ let l:lang_flag = ale#c#GetLanguageFlag(
+ \ a:buffer,
+ \ l:executable,
+ \ l:use_header_lang_flag,
+ \ l:header_exts,
+ \ 'c')
+
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
"
diff --git a/ale_linters/cpp/cc.vim b/ale_linters/cpp/cc.vim
index f8021531..1d35bb67 100644
--- a/ale_linters/cpp/cc.vim
+++ b/ale_linters/cpp/cc.vim
@@ -3,6 +3,7 @@
call ale#Set('cpp_cc_executable', '<auto>')
call ale#Set('cpp_cc_options', '-std=c++14 -Wall')
+call ale#Set('cpp_cc_use_header_lang_flag', -1)
call ale#Set('cpp_cc_header_exts', ['h', 'hpp'])
function! ale_linters#cpp#cc#GetExecutable(buffer) abort
@@ -23,8 +24,6 @@ endfunction
function! ale_linters#cpp#cc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
let l:ale_flags = ale#Var(a:buffer, 'cpp_cc_options')
- let l:header_exts = ale#Var(a:buffer, 'cpp_cc_header_exts')
- let l:lang_flag = ale#c#GetLanguageFlag(a:buffer, l:header_exts, 'c++')
if l:cflags =~# '-std='
let l:ale_flags = substitute(
@@ -34,6 +33,18 @@ function! ale_linters#cpp#cc#GetCommand(buffer, output) abort
\ 'g')
endif
+ " Select the correct language flag depending on the executable, options
+ " and file extension
+ let l:executable = ale_linters#cpp#cc#GetExecutable(a:buffer)
+ let l:use_header_lang_flag = ale#Var(a:buffer, 'cpp_cc_use_header_lang_flag')
+ let l:header_exts = ale#Var(a:buffer, 'cpp_cc_header_exts')
+ let l:lang_flag = ale#c#GetLanguageFlag(
+ \ a:buffer,
+ \ l:executable,
+ \ l:use_header_lang_flag,
+ \ l:header_exts,
+ \ 'c++')
+
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
"