Add the cquery LSP #1475 #1594

This commit is contained in:
Ben Falconer 2018-06-06 17:03:15 +01:00
parent 641c0c797b
commit 20db9ab719
5 changed files with 108 additions and 4 deletions

View File

@ -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) | | 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) | | 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 | [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) | | 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| | 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/) | | 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 Some tools and build configurations can generate
[compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html) [compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
files. The `cppcheck`, `clangcheck` and `clangtidy` linters can read these files. The `cppcheck`, `clangcheck`, `clangtidy` and `cquery` linters can read
files for automatically determining the appropriate compiler flags to use. these files for automatically determining the appropriate compiler flags to
use.
For linting with compilers like `gcc` and `clang`, and with other tools, you 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 will need to tell ALE which compiler flags to use yourself. You can use

View File

@ -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',
\})

View File

@ -156,6 +156,26 @@ g:ale_cpp_cpplint_options *g:ale_cpp_cpplint_options*
This variable can be changed to modify flags given to cpplint. This variable can be changed to modify flags given to cpplint.
===============================================================================
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* flawfinder *ale-cpp-flawfinder*

View File

@ -44,6 +44,7 @@ CONTENTS *ale-contents*
clangtidy...........................|ale-cpp-clangtidy| clangtidy...........................|ale-cpp-clangtidy|
cppcheck............................|ale-cpp-cppcheck| cppcheck............................|ale-cpp-cppcheck|
cpplint.............................|ale-cpp-cpplint| cpplint.............................|ale-cpp-cpplint|
cquery..............................|ale-cpp-cquery|
flawfinder..........................|ale-cpp-flawfinder| flawfinder..........................|ale-cpp-flawfinder|
gcc.................................|ale-cpp-gcc| gcc.................................|ale-cpp-gcc|
c#....................................|ale-cs-options| c#....................................|ale-cs-options|
@ -319,7 +320,7 @@ Notes:
* Bash: `shell` (-n flag), `shellcheck`, `shfmt` * Bash: `shell` (-n flag), `shellcheck`, `shfmt`
* Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt` * Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt`
* C: `cppcheck`, `cpplint`!!, `clang`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc` * 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`!! * CUDA: `nvcc`!!
* C#: `mcs`, `mcsc`!! * C#: `mcs`, `mcsc`!!
* Chef: `foodcritic` * Chef: `foodcritic`

View File

@ -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(''))