2017-01-12 09:33:55 +00:00
|
|
|
" Author: Daniel Schemala <istjanichtzufassen@gmail.com>
|
|
|
|
" Description: rustc for rust files
|
|
|
|
|
2018-08-10 20:50:52 +00:00
|
|
|
call ale#Set('rust_rustc_options', '-Z no-codegen')
|
2017-12-19 18:10:29 +00:00
|
|
|
|
|
|
|
function! ale_linters#rust#rustc#RustcCommand(buffer) abort
|
2017-01-12 09:33:55 +00:00
|
|
|
" Try to guess the library search path. If the project is managed by cargo,
|
|
|
|
" it's usually <project root>/target/debug/deps/ or
|
|
|
|
" <project root>/target/release/deps/
|
2017-12-19 18:10:29 +00:00
|
|
|
let l:cargo_file = ale#path#FindNearestFile(a:buffer, 'Cargo.toml')
|
2017-01-12 09:33:55 +00:00
|
|
|
|
2017-08-10 23:31:42 +00:00
|
|
|
if l:cargo_file isnot# ''
|
2017-12-19 18:10:29 +00:00
|
|
|
let l:root = fnamemodify(l:cargo_file, ':h')
|
|
|
|
let l:dependencies = ' -L ' . ale#Escape(ale#path#GetAbsPath(l:root, 'target/debug/deps'))
|
|
|
|
\ . ' -L ' . ale#Escape(ale#path#GetAbsPath(l:root, 'target/release/deps'))
|
2017-01-12 09:33:55 +00:00
|
|
|
else
|
|
|
|
let l:dependencies = ''
|
|
|
|
endif
|
|
|
|
|
2017-12-19 18:10:29 +00:00
|
|
|
let l:options = ale#Var(a:buffer, 'rust_rustc_options')
|
|
|
|
|
|
|
|
return 'rustc --error-format=json'
|
|
|
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
|
|
|
\ . l:dependencies . ' -'
|
2017-01-12 09:33:55 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('rust', {
|
|
|
|
\ 'name': 'rustc',
|
|
|
|
\ 'executable': 'rustc',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'command': function('ale_linters#rust#rustc#RustcCommand'),
|
2017-02-07 21:17:03 +00:00
|
|
|
\ 'callback': 'ale#handlers#rust#HandleRustErrors',
|
2017-01-12 09:33:55 +00:00
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\})
|