summaryrefslogtreecommitdiff
path: root/ale_linters/c
diff options
context:
space:
mode:
authorBjorn Neergaard <bjorn@neersighted.com>2018-11-29 14:57:35 -0700
committerBjorn Neergaard <bjorn@neersighted.com>2018-11-29 14:57:35 -0700
commitd2b0ae8108b2ee395d4eb43c49d68b322a023a30 (patch)
treebb8145e69bf1bcb8968b29cb1a68c47ceb83674d /ale_linters/c
parentef641dda80f45cb979bc93c2513c6e10cbd8e42a (diff)
parent0a384a49d371838903d8401c5358ec60f3f4266d (diff)
downloadale-d2b0ae8108b2ee395d4eb43c49d68b322a023a30.zip
Merge branch 'master' into sridhars
Diffstat (limited to 'ale_linters/c')
-rw-r--r--ale_linters/c/ccls.vim14
-rw-r--r--ale_linters/c/clang.vim17
-rw-r--r--ale_linters/c/clangd.vim12
-rw-r--r--ale_linters/c/clangtidy.vim30
-rw-r--r--ale_linters/c/cppcheck.vim9
-rw-r--r--ale_linters/c/cquery.vim28
-rw-r--r--ale_linters/c/flawfinder.vim12
-rw-r--r--ale_linters/c/gcc.vim17
8 files changed, 66 insertions, 73 deletions
diff --git a/ale_linters/c/ccls.vim b/ale_linters/c/ccls.vim
new file mode 100644
index 00000000..5dc2339f
--- /dev/null
+++ b/ale_linters/c/ccls.vim
@@ -0,0 +1,14 @@
+" Author: Ye Jingchen <ye.jingchen@gmail.com>, Ben Falconer <ben@falconers.me.uk>, jtalowell <jtalowell@protonmail.com>
+" Description: A language server for C
+
+call ale#Set('c_ccls_executable', 'ccls')
+call ale#Set('c_ccls_init_options', {})
+
+call ale#linter#Define('c', {
+\ 'name': 'ccls',
+\ 'lsp': 'stdio',
+\ 'executable_callback': ale#VarFunc('c_ccls_executable'),
+\ 'command': '%e',
+\ 'project_root_callback': 'ale#handlers#ccls#GetProjectRoot',
+\ 'initialization_options_callback':ale#VarFunc('c_ccls_init_options'),
+\})
diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim
index ddec4fcb..f1bd675b 100644
--- a/ale_linters/c/clang.vim
+++ b/ale_linters/c/clang.vim
@@ -4,29 +4,24 @@
call ale#Set('c_clang_executable', 'clang')
call ale#Set('c_clang_options', '-std=c11 -Wall')
-function! ale_linters#c#clang#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'c_clang_executable')
-endfunction
-
function! ale_linters#c#clang#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
- return ale#Escape(ale_linters#c#clang#GetExecutable(a:buffer))
- \ . ' -S -x c -fsyntax-only '
- \ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
- \ . l:cflags
- \ . ale#Var(a:buffer, 'c_clang_options') . ' -'
+ return '%e -S -x c -fsyntax-only'
+ \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
+ \ . ale#Pad(l:cflags)
+ \ . ale#Pad(ale#Var(a:buffer, 'c_clang_options')) . ' -'
endfunction
call ale#linter#Define('c', {
\ 'name': 'clang',
\ 'output_stream': 'stderr',
-\ 'executable_callback': 'ale_linters#c#clang#GetExecutable',
+\ 'executable_callback': ale#VarFunc('c_clang_executable'),
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#c#clang#GetCommand'}
\ ],
-\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
+\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})
diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim
index 5aa2e221..6cad601a 100644
--- a/ale_linters/c/clangd.vim
+++ b/ale_linters/c/clangd.vim
@@ -6,24 +6,18 @@ 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')
+ return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : ''
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 : '')
+ return '%e' . ale#Pad(ale#Var(a:buffer, 'c_clangd_options'))
endfunction
call ale#linter#Define('c', {
\ 'name': 'clangd',
\ 'lsp': 'stdio',
-\ 'executable_callback': 'ale_linters#c#clangd#GetExecutable',
+\ 'executable_callback': ale#VarFunc('c_clangd_executable'),
\ 'command_callback': 'ale_linters#c#clangd#GetCommand',
\ 'project_root_callback': 'ale_linters#c#clangd#GetProjectRoot',
\})
diff --git a/ale_linters/c/clangtidy.vim b/ale_linters/c/clangtidy.vim
index 47faa1ef..4f334655 100644
--- a/ale_linters/c/clangtidy.vim
+++ b/ale_linters/c/clangtidy.vim
@@ -10,44 +10,22 @@ call ale#Set('c_clangtidy_executable', 'clang-tidy')
" Consult the check list in clang-tidy's documentation:
" http://clang.llvm.org/extra/clang-tidy/checks/list.html
-call ale#Set('c_clangtidy_checks', ['*'])
+call ale#Set('c_clangtidy_checks', [])
" Set this option to manually set some options for clang-tidy.
" This will disable compile_commands.json detection.
call ale#Set('c_clangtidy_options', '')
call ale#Set('c_build_dir', '')
-function! ale_linters#c#clangtidy#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'c_clangtidy_executable')
-endfunction
-
-function! s:GetBuildDirectory(buffer) abort
- " Don't include build directory for header files, as compile_commands.json
- " files don't consider headers to be translation units, and provide no
- " commands for compiling header files.
- if expand('#' . a:buffer) =~# '\v\.(h|hpp)$'
- return ''
- endif
-
- let l:build_dir = ale#Var(a:buffer, 'c_build_dir')
-
- " c_build_dir has the priority if defined
- if !empty(l:build_dir)
- return l:build_dir
- endif
-
- return ale#c#FindCompileCommands(a:buffer)
-endfunction
-
function! ale_linters#c#clangtidy#GetCommand(buffer) abort
let l:checks = join(ale#Var(a:buffer, 'c_clangtidy_checks'), ',')
- let l:build_dir = s:GetBuildDirectory(a:buffer)
+ let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
" Get the extra options if we couldn't find a build directory.
let l:options = empty(l:build_dir)
\ ? ale#Var(a:buffer, 'c_clangtidy_options')
\ : ''
- return ale#Escape(ale_linters#c#clangtidy#GetExecutable(a:buffer))
+ return '%e'
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
\ . ' %s'
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
@@ -57,7 +35,7 @@ endfunction
call ale#linter#Define('c', {
\ 'name': 'clangtidy',
\ 'output_stream': 'stdout',
-\ 'executable_callback': 'ale_linters#c#clangtidy#GetExecutable',
+\ 'executable_callback': ale#VarFunc('c_clangtidy_executable'),
\ 'command_callback': 'ale_linters#c#clangtidy#GetCommand',
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
\ 'lint_file': 1,
diff --git a/ale_linters/c/cppcheck.vim b/ale_linters/c/cppcheck.vim
index 4db93f74..5e8c7936 100644
--- a/ale_linters/c/cppcheck.vim
+++ b/ale_linters/c/cppcheck.vim
@@ -4,10 +4,6 @@
call ale#Set('c_cppcheck_executable', 'cppcheck')
call ale#Set('c_cppcheck_options', '--enable=style')
-function! ale_linters#c#cppcheck#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'c_cppcheck_executable')
-endfunction
-
function! ale_linters#c#cppcheck#GetCommand(buffer) abort
" Search upwards from the file for compile_commands.json.
"
@@ -23,8 +19,7 @@ function! ale_linters#c#cppcheck#GetCommand(buffer) abort
\ : ''
return l:cd_command
- \ . ale#Escape(ale_linters#c#cppcheck#GetExecutable(a:buffer))
- \ . ' -q --language=c '
+ \ . '%e -q --language=c '
\ . l:compile_commands_option
\ . ale#Var(a:buffer, 'c_cppcheck_options')
\ . ' %t'
@@ -33,7 +28,7 @@ endfunction
call ale#linter#Define('c', {
\ 'name': 'cppcheck',
\ 'output_stream': 'both',
-\ 'executable_callback': 'ale_linters#c#cppcheck#GetExecutable',
+\ 'executable_callback': ale#VarFunc('c_cppcheck_executable'),
\ 'command_callback': 'ale_linters#c#cppcheck#GetCommand',
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
\})
diff --git a/ale_linters/c/cquery.vim b/ale_linters/c/cquery.vim
new file mode 100644
index 00000000..a20782a2
--- /dev/null
+++ b/ale_linters/c/cquery.vim
@@ -0,0 +1,28 @@
+" Author: Ben Falconer <ben@falconers.me.uk>, jtalowell <jtalowell@protonmail.com>
+" Description: A language server for C
+
+call ale#Set('c_cquery_executable', 'cquery')
+call ale#Set('c_cquery_cache_directory', expand('~/.cache/cquery'))
+
+function! ale_linters#c#cquery#GetProjectRoot(buffer) abort
+ let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json')
+
+ if empty(l:project_root)
+ let l:project_root = ale#path#FindNearestFile(a:buffer, '.cquery')
+ endif
+
+ return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : ''
+endfunction
+
+function! ale_linters#c#cquery#GetInitializationOptions(buffer) abort
+ return {'cacheDirectory': ale#Var(a:buffer, 'c_cquery_cache_directory')}
+endfunction
+
+call ale#linter#Define('c', {
+\ 'name': 'cquery',
+\ 'lsp': 'stdio',
+\ 'executable_callback': ale#VarFunc('c_cquery_executable'),
+\ 'command': '%e',
+\ 'project_root_callback': 'ale_linters#c#cquery#GetProjectRoot',
+\ 'initialization_options_callback': 'ale_linters#c#cquery#GetInitializationOptions',
+\})
diff --git a/ale_linters/c/flawfinder.vim b/ale_linters/c/flawfinder.vim
index df6fbebe..7e1f6769 100644
--- a/ale_linters/c/flawfinder.vim
+++ b/ale_linters/c/flawfinder.vim
@@ -6,18 +6,12 @@ call ale#Set('c_flawfinder_options', '')
call ale#Set('c_flawfinder_minlevel', 1)
call ale#Set('c_flawfinder_error_severity', 6)
-function! ale_linters#c#flawfinder#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'c_flawfinder_executable')
-endfunction
-
function! ale_linters#c#flawfinder#GetCommand(buffer) abort
-
" Set the minimum vulnerability level for flawfinder to bother with
let l:minlevel = ' --minlevel=' . ale#Var(a:buffer, 'c_flawfinder_minlevel')
- return ale#Escape(ale_linters#c#flawfinder#GetExecutable(a:buffer))
- \ . ' -CDQS'
- \ . ale#Var(a:buffer, 'c_flawfinder_options')
+ return '%e -CDQS'
+ \ . ale#Pad(ale#Var(a:buffer, 'c_flawfinder_options'))
\ . l:minlevel
\ . ' %t'
endfunction
@@ -25,7 +19,7 @@ endfunction
call ale#linter#Define('c', {
\ 'name': 'flawfinder',
\ 'output_stream': 'stdout',
-\ 'executable_callback': 'ale_linters#c#flawfinder#GetExecutable',
+\ 'executable_callback': ale#VarFunc('c_flawfinder_executable'),
\ 'command_callback': 'ale_linters#c#flawfinder#GetCommand',
\ 'callback': 'ale#handlers#flawfinder#HandleFlawfinderFormat',
\})
diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim
index 98563952..60ecb712 100644
--- a/ale_linters/c/gcc.vim
+++ b/ale_linters/c/gcc.vim
@@ -4,29 +4,24 @@
call ale#Set('c_gcc_executable', 'gcc')
call ale#Set('c_gcc_options', '-std=c11 -Wall')
-function! ale_linters#c#gcc#GetExecutable(buffer) abort
- return ale#Var(a:buffer, 'c_gcc_executable')
-endfunction
-
function! ale_linters#c#gcc#GetCommand(buffer, output) abort
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
" -iquote with the directory the file is in makes #include work for
" headers in the same directory.
- return ale#Escape(ale_linters#c#gcc#GetExecutable(a:buffer))
- \ . ' -S -x c -fsyntax-only '
- \ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
- \ . l:cflags
- \ . ale#Var(a:buffer, 'c_gcc_options') . ' -'
+ return '%e -S -x c -fsyntax-only'
+ \ . ' -iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
+ \ . ale#Pad(l:cflags)
+ \ . ale#Pad(ale#Var(a:buffer, 'c_gcc_options')) . ' -'
endfunction
call ale#linter#Define('c', {
\ 'name': 'gcc',
\ 'output_stream': 'stderr',
-\ 'executable_callback': 'ale_linters#c#gcc#GetExecutable',
+\ 'executable_callback': ale#VarFunc('c_gcc_executable'),
\ 'command_chain': [
\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#c#gcc#GetCommand'}
\ ],
-\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
+\ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
\})