为什么clang-tidy无法通过ALE设置其选项?

问题描述 投票:0回答:1

我可以使用源文件clang-tidy -p build/compile_commands.json filename.h运行clang-tidy,它可以按预期工作。当我通过vim打开文件时,我遇到了第一个#includes的错误,如果我不调用-p选项,就会发生这种情况。

[在我的vimrc中,我尝试将g:ale_c_build_dir设置为build,但这没有用,所以我尝试使用上面的g:ale_cpp_clangtidy_extra_options参数设置-p,但没有用。我可以确认是否已使用ALEInfo正确设置了这些值,显然它们并未在clang-tidy调用中使用。

vim-plugin clang-tidy
1个回答
0
投票

我目前正在尝试使用clang-tidy自己设置ALE,并最终使其与以下配置一起使用:

let g:ale_linters = {
\   'cpp': ['clangtidy'],
\   'c': ['clangtidy'],
\}
let g:ale_fixers={
\   'cpp': ['clang-format'],
\   '*': ['remove_trailing_lines', 'trim_whitespace'],
\}
let g:ale_cpp_clangtidy_checks = []
let g:ale_cpp_clangtidy_executable = 'clang-tidy'
let g:ale_c_parse_compile_commands=1
let g:ale_cpp_clangtidy_extra_options = ''
let g:ale_cpp_clangtidy_options = ''
let g:ale_set_balloons=1
let g:ale_linters_explicit=1
let g:airline#extensions#ale#enabled=1

如您所见,由于您的g:ale_c_build_dir_names位于g:ale_c_build_dir或[C0中,因此默认设置可以很好地完成工作(请参见以下文档的摘录),因为我跳过了compile_commands.jsonbuild的设置项目根目录的]目录。我注意到的一件事是,当用作ALE的棉短绒时,用c整齐的棉绒非常缓慢。

bin

和:

g:ale_c_build_dir_names                               
Type: List
Default: ['build', 'bin']

A list of directory names to be used when searching upwards from cpp
files to discover compilation databases with. For directory named 'foo',
ALE will search for 'foo/compile_commands.json' in all directories on and above
the directory containing the cpp file to find path to compilation database.
This feature is useful for the clang tools wrapped around LibTooling (namely
here, clang-tidy)
© www.soinside.com 2019 - 2024. All rights reserved.