-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1031 - Make the rust flags configurable
- Loading branch information
Showing
3 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
" Author: Daniel Schemala <[email protected]> | ||
" Description: rustc for rust files | ||
|
||
function! ale_linters#rust#rustc#RustcCommand(buffer_number) abort | ||
call ale#Set('rust_rustc_options', '-Z no-trans') | ||
|
||
function! ale_linters#rust#rustc#RustcCommand(buffer) abort | ||
" 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/ | ||
let l:cargo_file = ale#path#FindNearestFile(a:buffer_number, 'Cargo.toml') | ||
let l:cargo_file = ale#path#FindNearestFile(a:buffer, 'Cargo.toml') | ||
|
||
if l:cargo_file isnot# '' | ||
let l:project_root = fnamemodify(l:cargo_file, ':h') | ||
let l:dependencies = '-L ' . l:project_root . '/target/debug/deps -L ' . | ||
\ l:project_root . '/target/release/deps' | ||
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')) | ||
else | ||
let l:dependencies = '' | ||
endif | ||
|
||
return 'rustc --error-format=json -Z no-trans ' . l:dependencies . ' -' | ||
let l:options = ale#Var(a:buffer, 'rust_rustc_options') | ||
|
||
return 'rustc --error-format=json' | ||
\ . (!empty(l:options) ? ' ' . l:options : '') | ||
\ . l:dependencies . ' -' | ||
endfunction | ||
|
||
call ale#linter#Define('rust', { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Before: | ||
Save g:ale_rust_rustc_options | ||
|
||
unlet! g:ale_rust_rustc_options | ||
|
||
runtime ale_linters/rust/rustc.vim | ||
call ale#test#SetDirectory('/testplugin/test/command_callback') | ||
|
||
After: | ||
Restore | ||
|
||
unlet! b:ale_rust_rustc_options | ||
|
||
call ale#test#RestoreDirectory() | ||
call ale#linter#Reset() | ||
|
||
Execute(The default command should be correct): | ||
AssertEqual | ||
\ 'rustc --error-format=json -Z no-trans -', | ||
\ ale_linters#rust#rustc#RustcCommand(bufnr('')) | ||
|
||
Execute(The options should be configurable): | ||
let b:ale_rust_rustc_options = '--foo' | ||
|
||
AssertEqual | ||
\ 'rustc --error-format=json --foo -', | ||
\ ale_linters#rust#rustc#RustcCommand(bufnr('')) | ||
|
||
Execute(Some default paths should be included when the project is a Cargo project): | ||
call ale#test#SetFilename('cargo_paths/test.rs') | ||
|
||
AssertEqual | ||
\ 'rustc --error-format=json -Z no-trans' | ||
\ . ' -L ' . ale#Escape(ale#path#GetAbsPath(g:dir, 'cargo_paths/target/debug/deps')) | ||
\ . ' -L ' . ale#Escape(ale#path#GetAbsPath(g:dir, 'cargo_paths/target/release/deps')) | ||
\ . ' -', | ||
\ ale_linters#rust#rustc#RustcCommand(bufnr('')) |