From 56658fd3ada284a373afffb49b0ec2d66ad00445 Mon Sep 17 00:00:00 2001 From: Ye Jingchen Date: Wed, 26 Sep 2018 20:09:37 +0800 Subject: [PATCH] Add ccls support for C/C++/ObjC --- README.md | 6 +++--- ale_linters/c/ccls.vim | 30 ++++++++++++++++++++++++++++++ ale_linters/cpp/ccls.vim | 30 ++++++++++++++++++++++++++++++ ale_linters/objc/ccls.vim | 30 ++++++++++++++++++++++++++++++ doc/ale-c.txt | 31 +++++++++++++++++++++++++++++++ doc/ale-cpp.txt | 31 +++++++++++++++++++++++++++++++ doc/ale-objc.txt | 31 +++++++++++++++++++++++++++++++ doc/ale.txt | 3 +++ 8 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 ale_linters/c/ccls.vim create mode 100644 ale_linters/cpp/ccls.vim create mode 100644 ale_linters/objc/ccls.vim diff --git a/README.md b/README.md index b225c9c3..cea118ec 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,8 @@ formatting. | Awk | [gawk](https://www.gnu.org/software/gawk/)| | Bash | [language-server](https://github.com/mads-hartmann/bash-language-server), 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/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/), [uncrustify](https://github.com/uncrustify/uncrustify) | -| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [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), [clazy](https://github.com/KDE/clazy) !!, [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/), [uncrustify](https://github.com/uncrustify/uncrustify) | +| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) | +| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [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), [clazy](https://github.com/KDE/clazy) !!, [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/), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) | | 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, [uncrustify](https://github.com/uncrustify/uncrustify) | | Chef | [foodcritic](http://www.foodcritic.io/) | @@ -150,7 +150,7 @@ formatting. | Nim | [nim check](https://nim-lang.org/docs/nimc.html) !! | | nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) | | nroff | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)| -| Objective-C | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [uncrustify](https://github.com/uncrustify/uncrustify) | +| Objective-C | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) | | Objective-C++ | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [uncrustify](https://github.com/uncrustify/uncrustify) | | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) | | Pawn | [uncrustify](https://github.com/uncrustify/uncrustify) | diff --git a/ale_linters/c/ccls.vim b/ale_linters/c/ccls.vim new file mode 100644 index 00000000..0aad0a3d --- /dev/null +++ b/ale_linters/c/ccls.vim @@ -0,0 +1,30 @@ +" Author: Ye Jingchen , Ben Falconer , jtalowell +" Description: A language server for C + +call ale#Set('c_ccls_executable', 'ccls') +call ale#Set('c_ccls_init_options', {}) + +function! ale_linters#c#ccls#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') + + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + elseif empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') + endif + + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' +endfunction + +function! ale_linters#c#ccls#GetInitializationOptions(buffer) abort + return ale#Var(a:buffer, 'c_ccls_init_options') +endfunction + +call ale#linter#Define('c', { +\ 'name': 'ccls', +\ 'lsp': 'stdio', +\ 'executable_callback': ale#VarFunc('c_ccls_executable'), +\ 'command': '%e', +\ 'project_root_callback': 'ale_linters#c#ccls#GetProjectRoot', +\ 'initialization_options_callback': 'ale_linters#c#ccls#GetInitializationOptions', +\}) diff --git a/ale_linters/cpp/ccls.vim b/ale_linters/cpp/ccls.vim new file mode 100644 index 00000000..e63849c3 --- /dev/null +++ b/ale_linters/cpp/ccls.vim @@ -0,0 +1,30 @@ +" Author: Ye Jingchen , Ben Falconer , jtalowell +" Description: A language server for C++ + +call ale#Set('cpp_ccls_executable', 'ccls') +call ale#Set('cpp_ccls_init_options', {}) + +function! ale_linters#cpp#ccls#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') + + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + elseif empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') + endif + + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' +endfunction + +function! ale_linters#cpp#ccls#GetInitializationOptions(buffer) abort + return ale#Var(a:buffer, 'cpp_ccls_init_options') +endfunction + +call ale#linter#Define('cpp', { +\ 'name': 'ccls', +\ 'lsp': 'stdio', +\ 'executable_callback': ale#VarFunc('cpp_ccls_executable'), +\ 'command': '%e', +\ 'project_root_callback': 'ale_linters#cpp#ccls#GetProjectRoot', +\ 'initialization_options_callback': 'ale_linters#cpp#ccls#GetInitializationOptions', +\}) diff --git a/ale_linters/objc/ccls.vim b/ale_linters/objc/ccls.vim new file mode 100644 index 00000000..f354c7d7 --- /dev/null +++ b/ale_linters/objc/ccls.vim @@ -0,0 +1,30 @@ +" Author: Ye Jingchen , Ben Falconer , jtalowell +" Description: A language server for Objective-C + +call ale#Set('objc_ccls_executable', 'ccls') +call ale#Set('objc_ccls_init_options', {}) + +function! ale_linters#objc#ccls#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls-root') + + if empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + elseif empty(l:project_root) + let l:project_root = ale#path#FindNearestFile(a:buffer, '.ccls') + endif + + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' +endfunction + +function! ale_linters#objc#ccls#GetInitializationOptions(buffer) abort + return ale#Var(a:buffer, 'objc_ccls_init_options') +endfunction + +call ale#linter#Define('objc', { +\ 'name': 'ccls', +\ 'lsp': 'stdio', +\ 'executable_callback': ale#VarFunc('objc_ccls_executable'), +\ 'command': '%e', +\ 'project_root_callback': 'ale_linters#objc#ccls#GetProjectRoot', +\ 'initialization_options_callback': 'ale_linters#objc#ccls#GetInitializationOptions', +\}) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index c3820ba0..2a2a879e 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -281,5 +281,36 @@ g:ale_c_uncrustify_options *g:ale_c_uncrustify_options* This variable can be change to modify flags given to uncrustify. +=============================================================================== +ccls *ale-c-ccls* + +g:ale_c_ccls_executable *g:ale_c_ccls_executable* + *b:ale_c_ccls_executable* + Type: |String| + Default: `'ccls'` + + This variable can be changed to use a different executable for ccls. + + +g:ale_c_ccls_init_options *g:ale_c_ccls_init_options* + *b:ale_c_ccls_init_options* + Type: |Dictionary| + Default: `{}` + + This variable can be changed to customize ccls initialization options. + Example: > + { + \ 'cacheDirectory': '/tmp/ccls', + \ 'cacheFormat': 'binary', + \ 'diagnostics': { + \ 'onOpen': 0, + \ 'opChange': 1000, + \ }, + \ } +< + Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all + available options and explanations. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index 6c05c96d..47ba2c70 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -279,5 +279,36 @@ uncrustify *ale-cpp-uncrustify* See |ale-c-uncrustify| for information about the available options. +=============================================================================== +ccls *ale-cpp-ccls* + +g:ale_cpp_ccls_executable *g:ale_cpp_ccls_executable* + *b:ale_cpp_ccls_executable* + Type: |String| + Default: `'ccls'` + + This variable can be changed to use a different executable for ccls. + + +g:ale_cpp_ccls_init_options *g:ale_cpp_ccls_init_options* + *b:ale_cpp_ccls_init_options* + Type: |Dictionary| + Default: `{}` + + This variable can be changed to customize ccls initialization options. + Example: > + { + \ 'cacheDirectory': '/tmp/ccls', + \ 'cacheFormat': 'binary', + \ 'diagnostics': { + \ 'onOpen': 0, + \ 'opChange': 1000, + \ }, + \ } +< + Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all + available options and explanations. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-objc.txt b/doc/ale-objc.txt index 2d560267..0163175a 100644 --- a/doc/ale-objc.txt +++ b/doc/ale-objc.txt @@ -38,5 +38,36 @@ uncrustify *ale-objc-uncrustify* See |ale-c-uncrustify| for information about the available options. +=============================================================================== +ccls *ale-objc-ccls* + +g:ale_objc_ccls_executable *g:ale_objc_ccls_executable* + *b:ale_objc_ccls_executable* + Type: |String| + Default: `'ccls'` + + This variable can be changed to use a different executable for ccls. + + +g:ale_objc_ccls_init_options *g:ale_objc_ccls_init_options* + *b:ale_objc_ccls_init_options* + Type: |Dictionary| + Default: `{}` + + This variable can be changed to customize ccls initialization options. + Example: > + { + \ 'cacheDirectory': '/tmp/ccls', + \ 'cacheFormat': 'binary', + \ 'diagnostics': { + \ 'onOpen': 0, + \ 'opChange': 1000, + \ }, + \ } +< + Visit https://github.com/MaskRay/ccls/wiki/Initialization-options for all + available options and explanations. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index b166d9c5..00765e73 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -34,6 +34,7 @@ CONTENTS *ale-contents* flawfinder..........................|ale-c-flawfinder| gcc.................................|ale-c-gcc| uncrustify..........................|ale-c-uncrustify| + ccls................................|ale-c-ccls| chef..................................|ale-chef-options| foodcritic..........................|ale-chef-foodcritic| clojure...............................|ale-clojure-options| @@ -55,6 +56,7 @@ CONTENTS *ale-contents* flawfinder..........................|ale-cpp-flawfinder| gcc.................................|ale-cpp-gcc| uncrustify..........................|ale-cpp-uncrustify| + ccls................................|ale-cpp-ccls| c#....................................|ale-cs-options| mcs.................................|ale-cs-mcs| mcsc................................|ale-cs-mcsc| @@ -185,6 +187,7 @@ CONTENTS *ale-contents* clang...............................|ale-objc-clang| clangd..............................|ale-objc-clangd| uncrustify..........................|ale-objc-uncrustify| + ccls................................|ale-objc-ccls| objcpp................................|ale-objcpp-options| clang...............................|ale-objcpp-clang| clangd..............................|ale-objcpp-clangd|