All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Daniel Schemala <istjanichtzufassen@gmail.com>,
2 " Ivan Petkov <ivanppetkov@gmail.com>
3 " Description: rustc invoked by cargo for rust files
5 call ale#Set('rust_cargo_use_check', 1)
6 call ale#Set('rust_cargo_check_all_targets', 0)
7 call ale#Set('rust_cargo_check_examples', 0)
8 call ale#Set('rust_cargo_check_tests', 0)
9 call ale#Set('rust_cargo_avoid_whole_workspace', 1)
10 call ale#Set('rust_cargo_default_feature_behavior', 'default')
11 call ale#Set('rust_cargo_include_features', '')
12 call ale#Set('rust_cargo_use_clippy', 0)
13 call ale#Set('rust_cargo_clippy_options', '')
14 call ale#Set('rust_cargo_target_dir', '')
16 function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
17 if ale#path#FindNearestFile(a:bufnr, 'Cargo.toml') isnot# ''
20 " if there is no Cargo.toml file, we don't use cargo even if it exists,
21 " so we return '', because executable('') apparently always fails
26 function! ale_linters#rust#cargo#GetCwd(buffer) abort
27 if ale#Var(a:buffer, 'rust_cargo_avoid_whole_workspace')
28 let l:nearest_cargo = ale#path#FindNearestFile(a:buffer, 'Cargo.toml')
29 let l:nearest_cargo_dir = fnamemodify(l:nearest_cargo, ':h')
31 if l:nearest_cargo_dir isnot# '.'
32 return l:nearest_cargo_dir
39 function! ale_linters#rust#cargo#GetCommand(buffer, version) abort
40 let l:use_check = ale#Var(a:buffer, 'rust_cargo_use_check')
41 \ && ale#semver#GTE(a:version, [0, 17, 0])
42 let l:use_all_targets = ale#Var(a:buffer, 'rust_cargo_check_all_targets')
43 \ && ale#semver#GTE(a:version, [0, 22, 0])
44 let l:use_examples = ale#Var(a:buffer, 'rust_cargo_check_examples')
45 \ && ale#semver#GTE(a:version, [0, 22, 0])
46 let l:use_tests = ale#Var(a:buffer, 'rust_cargo_check_tests')
47 \ && ale#semver#GTE(a:version, [0, 22, 0])
48 let l:target_dir = ale#Var(a:buffer, 'rust_cargo_target_dir')
49 let l:use_target_dir = !empty(l:target_dir)
50 \ && ale#semver#GTE(a:version, [0, 17, 0])
52 let l:include_features = ale#Var(a:buffer, 'rust_cargo_include_features')
54 if !empty(l:include_features)
55 let l:include_features = ' --features ' . ale#Escape(l:include_features)
58 let l:default_feature_behavior = ale#Var(a:buffer, 'rust_cargo_default_feature_behavior')
60 if l:default_feature_behavior is# 'all'
61 let l:include_features = ''
62 let l:default_feature = ' --all-features'
63 elseif l:default_feature_behavior is# 'none'
64 let l:default_feature = ' --no-default-features'
66 let l:default_feature = ''
69 let l:subcommand = l:use_check ? 'check' : 'build'
70 let l:clippy_options = ''
72 if ale#Var(a:buffer, 'rust_cargo_use_clippy')
73 let l:subcommand = 'clippy'
74 let l:clippy_options = ale#Var(a:buffer, 'rust_cargo_clippy_options')
76 if l:clippy_options =~# '^-- '
77 let l:clippy_options = join(split(l:clippy_options, '-- '))
80 if l:clippy_options isnot# ''
81 let l:clippy_options = ' -- ' . l:clippy_options
87 \ . (l:use_all_targets ? ' --all-targets' : '')
88 \ . (l:use_examples ? ' --examples' : '')
89 \ . (l:use_tests ? ' --tests' : '')
90 \ . (l:use_target_dir ? (' --target-dir ' . ale#Escape(l:target_dir)) : '')
91 \ . ' --frozen --message-format=json -q'
93 \ . l:include_features
97 call ale#linter#Define('rust', {
99 \ 'executable': function('ale_linters#rust#cargo#GetCargoExecutable'),
100 \ 'cwd': function('ale_linters#rust#cargo#GetCwd'),
101 \ 'command': {buffer -> ale#semver#RunWithVersionCheck(
103 \ ale_linters#rust#cargo#GetCargoExecutable(buffer),
105 \ function('ale_linters#rust#cargo#GetCommand'),
107 \ 'callback': 'ale#handlers#rust#HandleRustErrors',
108 \ 'output_stream': 'both',