diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | ale_linters/c/clangd.vim | 29 | ||||
-rw-r--r-- | doc/ale-c.txt | 19 | ||||
-rw-r--r-- | doc/ale.txt | 3 | ||||
-rw-r--r-- | test/command_callback/clangd_paths/compile_commands.json | 0 | ||||
-rw-r--r-- | test/command_callback/test_c_clangd_command_callbacks.vader | 32 |
6 files changed, 83 insertions, 2 deletions
@@ -97,7 +97,7 @@ 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/), [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/), [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), [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| diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim new file mode 100644 index 00000000..5aa2e221 --- /dev/null +++ b/ale_linters/c/clangd.vim @@ -0,0 +1,29 @@ +" Author: Andrey Melentyev <andrey.melentyev@protonmail.com> +" Description: Clangd language server + +call ale#Set('c_clangd_executable', 'clangd') +call ale#Set('c_clangd_options', '') + +function! ale_linters#c#clangd#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') : '' +endfunction + +function! ale_linters#c#clangd#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'c_clangd_executable') +endfunction + +function! ale_linters#c#clangd#GetCommand(buffer) abort + let l:executable = ale_linters#c#clangd#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'c_clangd_options') + + return ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') +endfunction + +call ale#linter#Define('c', { +\ 'name': 'clangd', +\ 'lsp': 'stdio', +\ 'executable_callback': 'ale_linters#c#clangd#GetExecutable', +\ 'command_callback': 'ale_linters#c#clangd#GetCommand', +\ 'project_root_callback': 'ale_linters#c#clangd#GetProjectRoot', +\}) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index c41f3bc8..acff722c 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -64,6 +64,25 @@ g:ale_c_clang_options *g:ale_c_clang_options* =============================================================================== +clangd *ale-c-clangd* + +g:ale_c_clangd_executable *g:ale_c_clangd_executable* + *b:ale_c_clangd_executable* + Type: |String| + Default: `'clangd'` + + This variable can be changed to use a different executable for clangd. + + +g:ale_c_clangd_options *g:ale_c_clangd_options* + *b:ale_c_clangd_options* + Type: |String| + Default: `''` + + This variable can be changed to modify flags given to clangd. + + +=============================================================================== clang-format *ale-c-clangformat* g:ale_c_clangformat_executable *g:ale_c_clangformat_executable* diff --git a/doc/ale.txt b/doc/ale.txt index 1a75c29c..8182c27a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -26,6 +26,7 @@ CONTENTS *ale-contents* gawk................................|ale-awk-gawk| c.....................................|ale-c-options| clang...............................|ale-c-clang| + clangd..............................|ale-c-clangd| clang-format........................|ale-c-clangformat| clangtidy...........................|ale-c-clangtidy| cppcheck............................|ale-c-cppcheck| @@ -335,7 +336,7 @@ Notes: * Awk: `gawk` * Bash: `language-server`, `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`, `clangd`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc` * C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `cquery`, `flawfinder`, `gcc` * CUDA: `nvcc`!! * C#: `mcs`, `mcsc`!! diff --git a/test/command_callback/clangd_paths/compile_commands.json b/test/command_callback/clangd_paths/compile_commands.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/clangd_paths/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 new file mode 100644 index 00000000..c8c10b67 --- /dev/null +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -0,0 +1,32 @@ +Before: + call ale#assert#SetUpLinterTest('c', 'clangd') + + Save &filetype + let &filetype = 'c' + +After: + call ale#assert#TearDownLinterTest() + +Execute(The language string should be correct): + AssertLSPLanguage 'c' + +Execute(The default executable should be correct): + AssertLinter 'clangd', ale#Escape('clangd') + +Execute(The project root should be detected correctly): + AssertLSPProject '' + + call ale#test#SetFilename('clangd_paths/dummy.c') + + AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths') + +Execute(The executable should be configurable): + let g:ale_c_clangd_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') + +Execute(The options should be configurable): + let b:ale_c_clangd_options = '-compile-commands-dir=foo' + + AssertLinter 'clangd', ale#Escape('clangd') . ' ' . b:ale_c_clangd_options + |