From 212e3b0b2f36937eac126a7718d6997963b12c68 Mon Sep 17 00:00:00 2001 From: kodemeister Date: Tue, 7 Aug 2018 01:33:25 +0600 Subject: [PATCH 1/3] Use .cquery file to detect the project root --- ale_linters/c/cquery.vim | 3 +++ ale_linters/cpp/cquery.vim | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ale_linters/c/cquery.vim b/ale_linters/c/cquery.vim index 7daf9f76..225fda57 100644 --- a/ale_linters/c/cquery.vim +++ b/ale_linters/c/cquery.vim @@ -6,6 +6,9 @@ call ale#Set('c_cquery_cache_directory', expand('~/.cache/cquery')) function! ale_linters#c#cquery#GetProjectRoot(buffer) abort let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, '.cquery') + endif return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' endfunction diff --git a/ale_linters/cpp/cquery.vim b/ale_linters/cpp/cquery.vim index 39eebce3..7318da40 100644 --- a/ale_linters/cpp/cquery.vim +++ b/ale_linters/cpp/cquery.vim @@ -6,7 +6,9 @@ call ale#Set('cpp_cquery_cache_directory', expand('~/.cache/cquery')) function! ale_linters#cpp#cquery#GetProjectRoot(buffer) abort let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') - + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, '.cquery') + endif return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' endfunction From cc84c19451e3aa57eb45966b37f114a2c5941aab Mon Sep 17 00:00:00 2001 From: kodemeister Date: Thu, 9 Aug 2018 09:02:16 +0600 Subject: [PATCH 2/3] Add C/C++ tests for cquery LSP linter --- .../compile_commands.json | 0 .../cquery_paths/with_cquery/.cquery | 0 .../test_c_cquery_command_callbacks.vader | 33 +++++++++++++++++++ .../test_cpp_cquery_command_callbacks.vader | 14 ++++++++ 4 files changed, 47 insertions(+) create mode 100644 test/command_callback/cquery_paths/with_compile_commands_json/compile_commands.json create mode 100644 test/command_callback/cquery_paths/with_cquery/.cquery create mode 100644 test/command_callback/test_c_cquery_command_callbacks.vader diff --git a/test/command_callback/cquery_paths/with_compile_commands_json/compile_commands.json b/test/command_callback/cquery_paths/with_compile_commands_json/compile_commands.json new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/cquery_paths/with_cquery/.cquery b/test/command_callback/cquery_paths/with_cquery/.cquery new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/test_c_cquery_command_callbacks.vader b/test/command_callback/test_c_cquery_command_callbacks.vader new file mode 100644 index 00000000..13b7a567 --- /dev/null +++ b/test/command_callback/test_c_cquery_command_callbacks.vader @@ -0,0 +1,33 @@ +Before: + call ale#assert#SetUpLinterTest('c', 'cquery') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The project root should be detected correctly using compile_commands.json file): + AssertLSPProject '' + + call ale#test#SetFilename('cquery_paths/with_compile_commands_json/dummy.c') + + AssertLSPProject ale#path#Simplify(g:dir . '/cquery_paths/with_compile_commands_json') + +Execute(The project root should be detected correctly using .cquery file): + AssertLSPProject '' + + call ale#test#SetFilename('cquery_paths/with_cquery/dummy.c') + + AssertLSPProject ale#path#Simplify(g:dir . '/cquery_paths/with_cquery') + +Execute(The executable should be configurable): + AssertLinter 'cquery', ale#Escape('cquery') + + let b:ale_c_cquery_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') + +Execute(The cache directory should be configurable): + AssertLSPOptions {'cacheDirectory': expand('$HOME/.cache/cquery')} + + let b:ale_c_cquery_cache_directory = '/foo/bar' + + AssertLSPOptions {'cacheDirectory': '/foo/bar'} diff --git a/test/command_callback/test_cpp_cquery_command_callbacks.vader b/test/command_callback/test_cpp_cquery_command_callbacks.vader index b355d052..682c90d5 100644 --- a/test/command_callback/test_cpp_cquery_command_callbacks.vader +++ b/test/command_callback/test_cpp_cquery_command_callbacks.vader @@ -7,6 +7,20 @@ Before: After: call ale#assert#TearDownLinterTest() +Execute(The project root should be detected correctly using compile_commands.json file): + AssertLSPProject '' + + call ale#test#SetFilename('cquery_paths/with_compile_commands_json/dummy.cpp') + + AssertLSPProject ale#path#Simplify(g:dir . '/cquery_paths/with_compile_commands_json') + +Execute(The project root should be detected correctly using .cquery file): + AssertLSPProject '' + + call ale#test#SetFilename('cquery_paths/with_cquery/dummy.cpp') + + AssertLSPProject ale#path#Simplify(g:dir . '/cquery_paths/with_cquery') + Execute(The executable should be configurable): AssertLinter 'cquery', ale#Escape('cquery') From 0702e4699e3af612737a0a7a9e6c61726f1c9237 Mon Sep 17 00:00:00 2001 From: kodemeister Date: Thu, 9 Aug 2018 09:06:30 +0600 Subject: [PATCH 3/3] Add blank lines to conform the coding standards --- ale_linters/c/cquery.vim | 2 ++ ale_linters/cpp/cquery.vim | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ale_linters/c/cquery.vim b/ale_linters/c/cquery.vim index 225fda57..a20782a2 100644 --- a/ale_linters/c/cquery.vim +++ b/ale_linters/c/cquery.vim @@ -6,9 +6,11 @@ call ale#Set('c_cquery_cache_directory', expand('~/.cache/cquery')) function! ale_linters#c#cquery#GetProjectRoot(buffer) abort let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + if empty(l:project_root) let l:project_root = ale#path#FindNearestFile(a:buffer, '.cquery') endif + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' endfunction diff --git a/ale_linters/cpp/cquery.vim b/ale_linters/cpp/cquery.vim index 7318da40..b1c81989 100644 --- a/ale_linters/cpp/cquery.vim +++ b/ale_linters/cpp/cquery.vim @@ -6,9 +6,11 @@ call ale#Set('cpp_cquery_cache_directory', expand('~/.cache/cquery')) function! ale_linters#cpp#cquery#GetProjectRoot(buffer) abort let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + if empty(l:project_root) let l:project_root = ale#path#FindNearestFile(a:buffer, '.cquery') endif + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' endfunction