diff options
author | Nicolas Pauss <nicolas.pauss@intersec.com> | 2022-10-12 00:05:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 07:05:37 +0900 |
commit | 951a668b1490f0b3dcdcec6b4ebf3f626c0f416f (patch) | |
tree | 48eac8f7911b6fcfc1ad47ef02f84416628ccfcd /autoload | |
parent | f085227504076dff5224cbf10cb1bf83286188a9 (diff) | |
download | ale-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 'autoload')
-rw-r--r-- | autoload/ale/c.vim | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index 4a9b80fb..4a22c6fe 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -586,13 +586,37 @@ function! ale#c#IncludeOptions(include_paths) abort return join(l:option_list) endfunction -" Get the language flag depending on if the file is a header or not. -function! ale#c#GetLanguageFlag(buffer, header_exts, linter_lang) abort +" Get the language flag depending on on the executable, options and +" file extension +function! ale#c#GetLanguageFlag( +\ buffer, +\ executable, +\ use_header_lang_flag, +\ header_exts, +\ linter_lang_flag +\) abort + " Use only '-header' if the executable is 'clang' by default + if a:use_header_lang_flag == -1 + let l:use_header_lang_flag = a:executable =~# 'clang' + else + let l:use_header_lang_flag = a:use_header_lang_flag + endif + + " If we don't use the header language flag, return the default linter + " language flag + if !l:use_header_lang_flag + return a:linter_lang_flag + endif + + " Get the buffer file extension let l:buf_ext = expand('#' . a:buffer . ':e') + " If the buffer file is an header according to its extension, use + " the linter language flag + '-header', ex: 'c-header' if index(a:header_exts, l:buf_ext) >= 0 - return a:linter_lang . '-header' + return a:linter_lang_flag . '-header' endif - return a:linter_lang + " Else, use the default linter language flag + return a:linter_lang_flag endfunction |