summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorGagbo <Gagbo@users.noreply.github.com>2017-06-24 13:38:16 +0200
committerw0rp <w0rp@users.noreply.github.com>2017-06-24 12:38:16 +0100
commite98560a349f3381c8fc6ecb6bf149c337dcf17be (patch)
tree7ad98b85b261aa3e085df5e7aaa558687c35955d /ale_linters
parent026c4f304ee69b81c80f9969c62353546c847c7a (diff)
downloadale-e98560a349f3381c8fc6ecb6bf149c337dcf17be.zip
Added builddir option to clang-tidy to point to json folder (#688)
Detect compille_commands.json files for clang-tidy
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/cpp/clangtidy.vim30
1 files changed, 26 insertions, 4 deletions
diff --git a/ale_linters/cpp/clangtidy.vim b/ale_linters/cpp/clangtidy.vim
index f98b0852..94f5767c 100644
--- a/ale_linters/cpp/clangtidy.vim
+++ b/ale_linters/cpp/clangtidy.vim
@@ -1,4 +1,5 @@
-" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>
+" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
+" gagbo <gagbobada@gmail.com>
" Description: clang-tidy linter for cpp files
" Set this option to check the checks clang-tidy will apply.
@@ -8,15 +9,36 @@ let g:ale_cpp_clangtidy_checks = get(g:, 'ale_cpp_clangtidy_checks', ['*'])
" This will disable compile_commands.json detection.
let g:ale_cpp_clangtidy_options = get(g:, 'ale_cpp_clangtidy_options', '')
+" Set this option to manually point to the build directory for clang-tidy.
+" This will disable all the other clangtidy_options, since compilation
+" flags are contained in the json
+let g:ale_c_build_dir = get(g:, 'ale_c_build_dir', '')
+
+
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
let l:check_list = ale#Var(a:buffer, 'cpp_clangtidy_checks')
let l:check_option = !empty(l:check_list)
\ ? '-checks=' . ale#Escape(join(l:check_list, ',')) . ' '
\ : ''
let l:user_options = ale#Var(a:buffer, 'cpp_clangtidy_options')
- let l:extra_options = !empty(l:user_options)
- \ ? ' -- ' . l:user_options
- \ : ''
+ let l:user_build_dir = ale#Var(a:buffer, 'c_build_dir')
+
+ " c_build_dir has the priority if defined
+ if empty(l:user_build_dir)
+ let l:user_build_dir = ale#c#FindCompileCommands(a:buffer)
+ endif
+
+ " We check again if user_builddir stayed empty after the
+ " c_build_dir_names check
+ " If we found the compilation database we override the value of
+ " l:extra_options
+ if empty(l:user_build_dir)
+ let l:extra_options = !empty(l:user_options)
+ \ ? ' -- ' . l:user_options
+ \ : ''
+ else
+ let l:extra_options = ' -p ' . ale#Escape(l:user_build_dir)
+ endif
return 'clang-tidy ' . l:check_option . '%s' . l:extra_options
endfunction