summaryrefslogtreecommitdiff
path: root/ale_linters/c/ccls.vim
blob: d0fa566eb7f6e0b44c1faf27709abad5f2602d26 (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
29
30
31
32
" 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', {})

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')
    endif

    if 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',
\})