Enable C flag parsing by default

The options for parsing `make -n` and `compile_commands.json` flags
are now enabled by default, so people can start getting better flags
for their files by default.

`compile_commands.json` flags are now preferred over `make -n` results,
to make the options work better by default.
This commit is contained in:
w0rp 2020-08-09 04:19:14 +01:00
parent 681ca5fee8
commit affeed7a87
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
3 changed files with 24 additions and 11 deletions

View File

@ -816,6 +816,13 @@ setting. Consult the documentation for that setting for more information.
`b:ale_linters` can be used to select which tools you want to run, say if you
want to use only `gcc` for one project, and only `clang` for another.
ALE will attempt to parse `make -n` when a `Makefile` is found or load the flags
for files from `compile_commands.json` files. See `:help g:ale_c_parse_makefile`
and `:help g:ale_c_parse_compile_commands` for more information. See Clang's
documentation for [compile_commands.json files](https://clang.llvm.org/docs/JSONCompilationDatabase.html).
You should strongly consider generating them in your builds, which is easy to
do with CMake.
You may also configure buffer-local settings for linters with project-specific
vimrc files. [local_vimrc](https://github.com/LucHermitte/local_vimrc) can be
used for executing local vimrc files which can be shared in your project.

View File

@ -1,8 +1,8 @@
" Author: gagbo <gagbobada@gmail.com>, w0rp <devw0rp@gmail.com>, roel0 <postelmansroel@gmail.com>
" Description: Functions for integrating with C-family linters.
call ale#Set('c_parse_makefile', 0)
call ale#Set('c_parse_compile_commands', 0)
call ale#Set('c_parse_makefile', 1)
call ale#Set('c_parse_compile_commands', 1)
let s:sep = has('win32') ? '\' : '/'
" Set just so tests can override it.
@ -334,10 +334,6 @@ endfunction
function! ale#c#GetCFlags(buffer, output) abort
let l:cflags = v:null
if ale#Var(a:buffer, 'c_parse_makefile') && !empty(a:output)
let l:cflags = ale#c#ParseCFlagsFromMakeOutput(a:buffer, a:output)
endif
if ale#Var(a:buffer, 'c_parse_compile_commands')
let [l:root, l:json_file] = ale#c#FindCompileCommands(a:buffer)
@ -346,6 +342,12 @@ function! ale#c#GetCFlags(buffer, output) abort
endif
endif
if ale#Var(a:buffer, 'c_parse_makefile')
\&& !empty(a:output)
\&& !empty(l:cflags)
let l:cflags = ale#c#ParseCFlagsFromMakeOutput(a:buffer, a:output)
endif
if l:cflags is v:null
let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer))
endif

View File

@ -37,7 +37,7 @@ g:ale_c_build_dir *g:ale_c_build_dir*
g:ale_c_parse_compile_commands *g:ale_c_parse_compile_commands*
*b:ale_c_parse_compile_commands*
Type: |Number|
Default: `0`
Default: `1`
If set to `1`, ALE will parse `compile_commands.json` files to automatically
determine flags for C or C++ compilers. ALE will first search for the
@ -45,19 +45,23 @@ g:ale_c_parse_compile_commands *g:ale_c_parse_compile_commands*
`compile_commands.json` files in the directories for
|g:ale_c_build_dir_names|.
If |g:ale_c_parse_makefile| or |b:ale_c_parse_makefile| is set to `1`, the
output of `make -n` will be preferred over `compile_commands.json` files.
g:ale_c_parse_makefile *g:ale_c_parse_makefile*
*b:ale_c_parse_makefile*
Type: |Number|
Default: `0`
Default: `1`
If set to `1`, ALE will run `make -n` to automatically determine flags to
set for C or C++ compilers. This can make it easier to determine the correct
build flags to use for different files.
You might want to disable this option if `make -n` takes too long to run for
projects you work on.
If |g:ale_c_parse_compile_commands| or |b:ale_c_parse_compile_commands| is
set to `1`, flags taken from `compile_commands.json` will be preferred over
`make -n` output.
===============================================================================
astyle *ale-c-astyle*