diff options
-rw-r--r-- | ale_linters/c/clangd.vim | 7 | ||||
-rw-r--r-- | ale_linters/cpp/clangd.vim | 7 | ||||
-rw-r--r-- | test/command_callback/clangd_paths/with_build_dir/unusual_build_dir_name/compile_commands.json (renamed from test/command_callback/clangd_paths/compile_commands.json) | 0 | ||||
-rw-r--r-- | test/command_callback/clangd_paths/with_compile_commands/compile_commands.json | 0 | ||||
-rw-r--r-- | test/command_callback/test_c_clangd_command_callbacks.vader | 21 |
5 files changed, 31 insertions, 4 deletions
diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim index 0bb38d43..ab8a0259 100644 --- a/ale_linters/c/clangd.vim +++ b/ale_linters/c/clangd.vim @@ -3,9 +3,14 @@ call ale#Set('c_clangd_executable', 'clangd') call ale#Set('c_clangd_options', '') +call ale#Set('c_build_dir', '') function! ale_linters#c#clangd#GetCommand(buffer) abort - return '%e -x c' . ale#Pad(ale#Var(a:buffer, 'c_clangd_options')) + let l:build_dir = ale#c#GetBuildDirectory(a:buffer) + + return '%e -x c' + \ . ale#Pad(ale#Var(a:buffer, 'c_clangd_options')) + \ . (!empty(l:build_dir) ? ' -compile-commands-dir=' . ale#Escape(l:build_dir) : '') endfunction call ale#linter#Define('c', { diff --git a/ale_linters/cpp/clangd.vim b/ale_linters/cpp/clangd.vim index fab605f4..14f3fe55 100644 --- a/ale_linters/cpp/clangd.vim +++ b/ale_linters/cpp/clangd.vim @@ -3,9 +3,14 @@ call ale#Set('cpp_clangd_executable', 'clangd') call ale#Set('cpp_clangd_options', '') +call ale#Set('c_build_dir', '') function! ale_linters#cpp#clangd#GetCommand(buffer) abort - return '%e' . ale#Pad(ale#Var(a:buffer, 'cpp_clangd_options')) + let l:build_dir = ale#c#GetBuildDirectory(a:buffer) + + return '%e' + \ . ale#Pad(ale#Var(a:buffer, 'cpp_clangd_options')) + \ . (!empty(l:build_dir) ? ' -compile-commands-dir=' . ale#Escape(l:build_dir) : '') endfunction call ale#linter#Define('cpp', { diff --git a/test/command_callback/clangd_paths/compile_commands.json b/test/command_callback/clangd_paths/with_build_dir/unusual_build_dir_name/compile_commands.json index e69de29b..e69de29b 100644 --- a/test/command_callback/clangd_paths/compile_commands.json +++ b/test/command_callback/clangd_paths/with_build_dir/unusual_build_dir_name/compile_commands.json diff --git a/test/command_callback/clangd_paths/with_compile_commands/compile_commands.json b/test/command_callback/clangd_paths/with_compile_commands/compile_commands.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/clangd_paths/with_compile_commands/compile_commands.json diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader index 15726163..555122f6 100644 --- a/test/command_callback/test_c_clangd_command_callbacks.vader +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -4,6 +4,11 @@ Before: Save &filetype let &filetype = 'c' + Save b:ale_c_clangd_options + Save b:ale_c_build_dir + Save b:ale_c_build_dir_names + Save b:ale_c_parse_compile_commands + let b:command_tail = ' -x c' After: @@ -22,9 +27,9 @@ Execute(The project root should be detected correctly): AssertLSPProject '' - call ale#test#SetFilename('clangd_paths/dummy.c') + call ale#test#SetFilename('clangd_paths/with_compile_commands/dummy.c') - AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths') + AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths/with_compile_commands') Execute(The executable should be configurable): let g:ale_c_clangd_executable = 'foobar' @@ -36,3 +41,15 @@ Execute(The options should be configurable): AssertLinter 'clangd', ale#Escape('clangd') . b:command_tail . ' ' . b:ale_c_clangd_options +Execute(The compile command database should be detected correctly): + call ale#test#SetFilename('clangd_paths/with_build_dir/dummy_src/dummy.c') + + let b:ale_c_clangd_options = '' + let b:ale_c_build_dir = '' + let b:ale_c_build_dir_names = ['unusual_build_dir_name'] + let b:ale_c_parse_compile_commands = 1 + + AssertLinter 'clangd', ale#Escape('clangd') . b:command_tail + \ . ' -compile-commands-dir=' + \ . ale#Escape(ale#path#Simplify(g:dir . '/clangd_paths/with_build_dir/unusual_build_dir_name')) + |