summaryrefslogtreecommitdiff
path: root/ale_linters/c/cquery.vim
blob: a20782a2d0d4f6af33db557d76102aee5cbda01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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',
\})