summaryrefslogtreecommitdiff
path: root/ale_linters/rust/cargo.vim
blob: 84e4be74ff99680a937201b8586e0d7add3a4c50 (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
" Author: Daniel Schemala <istjanichtzufassen@gmail.com>
" Description: rustc invoked by cargo for rust files

let g:ale_rust_cargo_use_check = get(g:, 'ale_rust_cargo_use_check', 0)

function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
    if ale#util#FindNearestFile(a:bufnr, 'Cargo.toml') !=# ''
        return 'cargo'
    else
        " if there is no Cargo.toml file, we don't use cargo even if it exists,
        " so we return '', because executable('') apparently always fails
        return ''
    endif
endfunction

function! ale_linters#rust#cargo#GetCommand(buffer) abort
    let l:command = g:ale_rust_cargo_use_check
    \   ? 'check'
    \   : 'build'

    return 'cargo ' . l:command . ' --frozen --message-format=json -q'
endfunction

call ale#linter#Define('rust', {
\   'name': 'cargo',
\   'executable_callback': 'ale_linters#rust#cargo#GetCargoExecutable',
\   'command_callback': 'ale_linters#rust#cargo#GetCommand',
\   'callback': 'ale#handlers#rust#HandleRustErrors',
\   'output_stream': 'stdout',
\   'lint_file': 1,
\})