ale/ale_linters/rust/cargo.vim

32 lines
1.1 KiB
VimL
Raw Normal View History

" 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
2017-08-10 19:31:42 -04:00
if ale#path#FindNearestFile(a:bufnr, 'Cargo.toml') isnot# ''
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 = ale#Var(a:buffer, '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',
2017-02-07 16:17:03 -05:00
\ 'callback': 'ale#handlers#rust#HandleRustErrors',
\ 'output_stream': 'both',
\ 'lint_file': 1,
\})