From affeed7a87ce54aff9506c0069da1f9f23e3dd01 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 9 Aug 2020 04:19:14 +0100 Subject: [PATCH] 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. --- README.md | 7 +++++++ autoload/ale/c.vim | 14 ++++++++------ doc/ale-c.txt | 14 +++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ad957bcb..6d1f8dd9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index 9b428700..591a0474 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -1,8 +1,8 @@ " Author: gagbo , w0rp , roel0 " 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 diff --git a/doc/ale-c.txt b/doc/ale-c.txt index efc26f93..53c141b3 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -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*