summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rw-r--r--ale_linters/cpp/cquery.vim34
-rw-r--r--doc/ale-cpp.txt20
-rw-r--r--doc/ale.txt3
-rw-r--r--test/command_callback/test_cpp_cquery_command_callbacks.vader48
5 files changed, 108 insertions, 4 deletions
diff --git a/README.md b/README.md
index c42e83f3..90ec9d44 100644
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@ formatting.
| Bash | shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
| Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) |
-| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) |
+| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) |
| CUDA | [nvcc](http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html) |
| C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) see:`help ale-cs-mcs` for details, [mcsc](http://www.mono-project.com/docs/about-mono/languages/csharp/) !! see:`help ale-cs-mcsc` for details and configuration|
| Chef | [foodcritic](http://www.foodcritic.io/) |
@@ -749,8 +749,9 @@ ALE cannot easily detect which compiler flags to use.
Some tools and build configurations can generate
[compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
-files. The `cppcheck`, `clangcheck` and `clangtidy` linters can read these
-files for automatically determining the appropriate compiler flags to use.
+files. The `cppcheck`, `clangcheck`, `clangtidy` and `cquery` linters can read
+these files for automatically determining the appropriate compiler flags to
+use.
For linting with compilers like `gcc` and `clang`, and with other tools, you
will need to tell ALE which compiler flags to use yourself. You can use
diff --git a/ale_linters/cpp/cquery.vim b/ale_linters/cpp/cquery.vim
new file mode 100644
index 00000000..dbaed520
--- /dev/null
+++ b/ale_linters/cpp/cquery.vim
@@ -0,0 +1,34 @@
+" Author: Ben Falconer <ben@falconers.me.uk>
+" Description: A language server for C++
+
+call ale#Set('cpp_cquery_executable', 'cquery')
+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')
+
+ return !empty(l:project_root) ? fnamemodify(l:project_root, ':h:h') : ''
+endfunction
+
+function! ale_linters#cpp#cquery#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'cpp_cquery_executable')
+endfunction
+
+function! ale_linters#cpp#cquery#GetCommand(buffer) abort
+ let l:executable = ale_linters#cpp#cquery#GetExecutable(a:buffer)
+ return ale#Escape(l:executable)
+endfunction
+
+function! ale_linters#cpp#cquery#GetInitializationOptions(buffer) abort
+ return {'cacheDirectory': ale#Var(a:buffer, 'cpp_cquery_cache_directory')}
+endfunction
+
+call ale#linter#Define('cpp', {
+\ 'name': 'cquery',
+\ 'lsp': 'stdio',
+\ 'executable_callback': 'ale_linters#cpp#cquery#GetExecutable',
+\ 'command_callback': 'ale_linters#cpp#cquery#GetCommand',
+\ 'project_root_callback': 'ale_linters#cpp#cquery#GetProjectRoot',
+\ 'initialization_options_callback': 'ale_linters#cpp#cquery#GetInitializationOptions',
+\ 'language': 'cpp',
+\})
diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt
index 05e54799..8bd111e4 100644
--- a/doc/ale-cpp.txt
+++ b/doc/ale-cpp.txt
@@ -157,6 +157,26 @@ g:ale_cpp_cpplint_options *g:ale_cpp_cpplint_options*
===============================================================================
+cquery *ale-cpp-cquery*
+
+g:ale_cpp_cquery_executable *g:ale_cpp_cquery_executable*
+ *b:ale_cpp_cquery_executable*
+ Type: |String|
+ Default: `'cquery'`
+
+ This variable can be changed to use a different executable for cquery.
+
+
+g:ale_cpp_cquery_cache_directory *g:ale_cpp_cquery_cache_directory*
+ *b:ale_cpp_cquery_cache_directory*
+ Type: |String|
+ Default: `'~/.cache/cquery'`
+
+ This variable can be changed to decide which directory cquery uses for its
+ cache.
+
+
+===============================================================================
flawfinder *ale-cpp-flawfinder*
g:ale_cpp_flawfinder_executable *g:ale_cpp_flawfinder_executable*
diff --git a/doc/ale.txt b/doc/ale.txt
index 0808e2ac..0531589c 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -44,6 +44,7 @@ CONTENTS *ale-contents*
clangtidy...........................|ale-cpp-clangtidy|
cppcheck............................|ale-cpp-cppcheck|
cpplint.............................|ale-cpp-cpplint|
+ cquery..............................|ale-cpp-cquery|
flawfinder..........................|ale-cpp-flawfinder|
gcc.................................|ale-cpp-gcc|
c#....................................|ale-cs-options|
@@ -319,7 +320,7 @@ Notes:
* Bash: `shell` (-n flag), `shellcheck`, `shfmt`
* Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt`
* C: `cppcheck`, `cpplint`!!, `clang`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc`
-* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `flawfinder`, `gcc`
+* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `cquery`, `flawfinder`, `gcc`
* CUDA: `nvcc`!!
* C#: `mcs`, `mcsc`!!
* Chef: `foodcritic`
diff --git a/test/command_callback/test_cpp_cquery_command_callbacks.vader b/test/command_callback/test_cpp_cquery_command_callbacks.vader
new file mode 100644
index 00000000..89a3e225
--- /dev/null
+++ b/test/command_callback/test_cpp_cquery_command_callbacks.vader
@@ -0,0 +1,48 @@
+" Author: Ben Falconer <ben@falconers.me.uk>
+" Description: A language server for C++
+
+Before:
+ Save g:ale_cpp_cquery_executable
+ Save g:ale_cpp_cquery_cache_directory
+
+ unlet! g:ale_cpp_cquery_executable
+ unlet! b:ale_cpp_cquery_executable
+ unlet! g:ale_cpp_cquery_cache_directory
+ unlet! b:ale_cpp_cquery_cache_directory
+
+ runtime ale_linters/cpp/cquery.vim
+
+After:
+ Restore
+ unlet! b:ale_cpp_cquery_executable
+ unlet! b:ale_cpp_cquery_cache_directory
+ call ale#linter#Reset()
+
+Execute(The executable should be configurable):
+ AssertEqual 'cquery', ale_linters#cpp#cquery#GetExecutable(bufnr(''))
+
+ let b:ale_cpp_cquery_executable = 'foobar'
+
+ AssertEqual 'foobar', ale_linters#cpp#cquery#GetExecutable(bufnr(''))
+
+Execute(The executable should be used in the command):
+ AssertEqual
+ \ ale#Escape('cquery'),
+ \ ale_linters#cpp#cquery#GetCommand(bufnr(''))
+
+ let b:ale_cpp_cquery_executable = 'foobar'
+
+ AssertEqual
+ \ ale#Escape('foobar'),
+ \ ale_linters#cpp#cquery#GetCommand(bufnr(''))
+
+Execute(The cache directory should be configurable):
+ AssertEqual
+ \ {'cacheDirectory': expand('$HOME/.cache/cquery')},
+ \ ale_linters#cpp#cquery#GetInitializationOptions(bufnr(''))
+
+ let b:ale_cpp_cquery_cache_directory = '/foo/bar'
+
+ AssertEqual
+ \ {'cacheDirectory': '/foo/bar'},
+ \ ale_linters#cpp#cquery#GetInitializationOptions(bufnr(''))