Merge pull request #1751 from melentye/master
Add Clangd language server support for C
This commit is contained in:
commit
9c849da8c4
@ -97,7 +97,7 @@ formatting.
|
|||||||
| Awk | [gawk](https://www.gnu.org/software/gawk/)|
|
| 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) |
|
| 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) |
|
| 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/) |
|
| 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|
|
||||||
|
29
ale_linters/c/clangd.vim
Normal file
29
ale_linters/c/clangd.vim
Normal file
@ -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',
|
||||||
|
\})
|
@ -63,6 +63,25 @@ g:ale_c_clang_options *g:ale_c_clang_options*
|
|||||||
This variable can be changed to modify flags given to clang.
|
This variable can be changed to modify flags given to clang.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
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*
|
clang-format *ale-c-clangformat*
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ CONTENTS *ale-contents*
|
|||||||
gawk................................|ale-awk-gawk|
|
gawk................................|ale-awk-gawk|
|
||||||
c.....................................|ale-c-options|
|
c.....................................|ale-c-options|
|
||||||
clang...............................|ale-c-clang|
|
clang...............................|ale-c-clang|
|
||||||
|
clangd..............................|ale-c-clangd|
|
||||||
clang-format........................|ale-c-clangformat|
|
clang-format........................|ale-c-clangformat|
|
||||||
clangtidy...........................|ale-c-clangtidy|
|
clangtidy...........................|ale-c-clangtidy|
|
||||||
cppcheck............................|ale-c-cppcheck|
|
cppcheck............................|ale-c-cppcheck|
|
||||||
@ -335,7 +336,7 @@ Notes:
|
|||||||
* Awk: `gawk`
|
* Awk: `gawk`
|
||||||
* Bash: `language-server`, `shell` (-n flag), `shellcheck`, `shfmt`
|
* Bash: `language-server`, `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`, `clangd`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc`
|
||||||
* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `cquery`, `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`!!
|
||||||
|
32
test/command_callback/test_c_clangd_command_callbacks.vader
Normal file
32
test/command_callback/test_c_clangd_command_callbacks.vader
Normal file
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user