#1167 Use the make -n parsing for C++ compilers, and document the new option

This commit is contained in:
w0rp 2018-03-27 19:24:22 +01:00
parent 018831d601
commit 95ec9bb780
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
7 changed files with 44 additions and 24 deletions

View File

@ -8,15 +8,15 @@ function! ale_linters#cpp#clang#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'cpp_clang_executable')
endfunction
function! ale_linters#cpp#clang#GetCommand(buffer) abort
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
function! ale_linters#cpp#clang#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return ale#Escape(ale_linters#cpp#clang#GetExecutable(a:buffer))
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
\ . ale#c#IncludeOptions(l:paths)
\ . l:cflags
\ . ale#Var(a:buffer, 'cpp_clang_options') . ' -'
endfunction
@ -24,6 +24,9 @@ call ale#linter#Define('cpp', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
\ 'executable_callback': 'ale_linters#cpp#clang#GetExecutable',
\ 'command_callback': 'ale_linters#cpp#clang#GetCommand',
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#cpp#clang#GetCommand'},
\ ],
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\})

View File

@ -8,15 +8,15 @@ function! ale_linters#cpp#gcc#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'cpp_gcc_executable')
endfunction
function! ale_linters#cpp#gcc#GetCommand(buffer) abort
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
function! ale_linters#cpp#gcc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
return ale#Escape(ale_linters#cpp#gcc#GetExecutable(a:buffer))
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
\ . ale#c#IncludeOptions(l:paths)
\ . l:cflags
\ . ale#Var(a:buffer, 'cpp_gcc_options') . ' -'
endfunction
@ -24,6 +24,9 @@ call ale#linter#Define('cpp', {
\ 'name': 'g++',
\ 'output_stream': 'stderr',
\ 'executable_callback': 'ale_linters#cpp#gcc#GetExecutable',
\ 'command_callback': 'ale_linters#cpp#gcc#GetCommand',
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#cpp#gcc#GetCommand'},
\ ],
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\})

View File

@ -31,7 +31,18 @@ g:ale_c_build_dir *g:ale_c_build_dir*
database (it can be useful if multiple builds are in multiple build
subdirectories in the project tree).
This feature is also most useful for the clang tools linters, wrapped
aroung LibTooling (namely clang-tidy here)
around LibTooling (namely clang-tidy here)
g:ale_c_parse_makefile *g:ale_c_parse_makefile*
*b:ale_c_parse_makefile*
Type: |Number|
Default: `0`
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.
===============================================================================
clang *ale-c-clang*

View File

@ -5,8 +5,11 @@ ALE C++ Integration *ale-cpp-options*
===============================================================================
Global Options
The |g:ale_c_build_dir_names| and |g:ale_c_build_dir| also apply to some C++
linters too.
The following C options also apply to some C++ linters too.
* |g:ale_c_build_dir_names|
* |g:ale_c_build_dir|
* |g:ale_c_parse_makefile|
===============================================================================

View File

@ -30,10 +30,10 @@ Execute(The executable should be configurable):
Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('clang++') . b:command_tail,
\ ale_linters#cpp#clang#GetCommand(bufnr(''))
\ ale_linters#cpp#clang#GetCommand(bufnr(''), [])
let b:ale_cpp_clang_executable = 'foobar'
AssertEqual
\ ale#Escape('foobar') . b:command_tail,
\ ale_linters#cpp#clang#GetCommand(bufnr(''))
\ ale_linters#cpp#clang#GetCommand(bufnr(''), [])

View File

@ -30,10 +30,10 @@ Execute(The executable should be configurable):
Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('gcc') . b:command_tail,
\ ale_linters#cpp#gcc#GetCommand(bufnr(''))
\ ale_linters#cpp#gcc#GetCommand(bufnr(''), [])
let b:ale_cpp_gcc_executable = 'foobar'
AssertEqual
\ ale#Escape('foobar') . b:command_tail,
\ ale_linters#cpp#gcc#GetCommand(bufnr(''))
\ ale_linters#cpp#gcc#GetCommand(bufnr(''), [])

View File

@ -146,7 +146,7 @@ Execute(The C++ GCC handler should include 'include' directories for projects wi
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/include')) . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''), [])
Execute(The C++ GCC handler should include 'include' directories for projects with a configure file):
runtime! ale_linters/cpp/gcc.vim
@ -159,7 +159,7 @@ Execute(The C++ GCC handler should include 'include' directories for projects wi
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/configure_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/configure_project/include')) . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''), [])
Execute(The C++ GCC handler should include root directories for projects with .h files in them):
runtime! ale_linters/cpp/gcc.vim
@ -172,7 +172,7 @@ Execute(The C++ GCC handler should include root directories for projects with .h
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/h_file_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/h_file_project')) . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''), [])
Execute(The C++ GCC handler should include root directories for projects with .hpp files in them):
runtime! ale_linters/cpp/gcc.vim
@ -185,7 +185,7 @@ Execute(The C++ GCC handler should include root directories for projects with .h
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/hpp_file_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/hpp_file_project')) . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''), [])
Execute(The C++ Clang handler should include 'include' directories for projects with a Makefile):
runtime! ale_linters/cpp/clang.vim
@ -198,7 +198,7 @@ Execute(The C++ Clang handler should include 'include' directories for projects
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/makefile_project/include')) . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
\ , ale_linters#cpp#clang#GetCommand(bufnr(''), [])
Execute(The C++ Clang handler should include 'include' directories for projects with a configure file):
runtime! ale_linters/cpp/clang.vim
@ -211,7 +211,7 @@ Execute(The C++ Clang handler should include 'include' directories for projects
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/configure_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/configure_project/include')) . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
\ , ale_linters#cpp#clang#GetCommand(bufnr(''), [])
Execute(The C++ Clang handler should include root directories for projects with .h files in them):
runtime! ale_linters/cpp/clang.vim
@ -224,7 +224,7 @@ Execute(The C++ Clang handler should include root directories for projects with
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/h_file_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/h_file_project')) . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
\ , ale_linters#cpp#clang#GetCommand(bufnr(''), [])
Execute(The C++ Clang handler should include root directories for projects with .hpp files in them):
runtime! ale_linters/cpp/clang.vim
@ -237,7 +237,7 @@ Execute(The C++ Clang handler should include root directories for projects with
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/hpp_file_project/subdir')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/hpp_file_project')) . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
\ , ale_linters#cpp#clang#GetCommand(bufnr(''), [])
Execute(The C++ Clang handler shoud use the include directory based on the .git location):
runtime! ale_linters/cpp/clang.vim
@ -258,7 +258,7 @@ Execute(The C++ Clang handler shoud use the include directory based on the .git
\ . '-iquote ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/git_and_nested_makefiles/src')) . ' '
\ . ' -I' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/git_and_nested_makefiles/include')) . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
\ , ale_linters#cpp#clang#GetCommand(bufnr(''), [])
Execute(The C++ ClangTidy handler should include json folders for projects with suitable build directory in them):
runtime! ale_linters/cpp/clangtidy.vim