mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Removed syntastic and replaced it with ale
Read more here: https://github.com/w0rp/ale
This commit is contained in:
68
sources_non_forked/ale/ale_linters/rust/cargo.vim
Normal file
68
sources_non_forked/ale/ale_linters/rust/cargo.vim
Normal file
@ -0,0 +1,68 @@
|
||||
" Author: Daniel Schemala <istjanichtzufassen@gmail.com>,
|
||||
" Ivan Petkov <ivanppetkov@gmail.com>
|
||||
" Description: rustc invoked by cargo for rust files
|
||||
|
||||
call ale#Set('rust_cargo_use_check', 1)
|
||||
call ale#Set('rust_cargo_check_all_targets', 0)
|
||||
call ale#Set('rust_cargo_default_feature_behavior', 'default')
|
||||
call ale#Set('rust_cargo_include_features', '')
|
||||
|
||||
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
|
||||
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#VersionCheck(buffer) abort
|
||||
return !ale#semver#HasVersion('cargo')
|
||||
\ ? 'cargo --version'
|
||||
\ : ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#rust#cargo#GetCommand(buffer, version_output) abort
|
||||
let l:version = ale#semver#GetVersion('cargo', a:version_output)
|
||||
|
||||
let l:use_check = ale#Var(a:buffer, 'rust_cargo_use_check')
|
||||
\ && ale#semver#GTE(l:version, [0, 17, 0])
|
||||
let l:use_all_targets = l:use_check
|
||||
\ && ale#Var(a:buffer, 'rust_cargo_check_all_targets')
|
||||
\ && ale#semver#GTE(l:version, [0, 22, 0])
|
||||
|
||||
let l:include_features = ale#Var(a:buffer, 'rust_cargo_include_features')
|
||||
if !empty(l:include_features)
|
||||
let l:include_features = ' --features ' . ale#Escape(l:include_features)
|
||||
endif
|
||||
|
||||
let l:default_feature_behavior = ale#Var(a:buffer, 'rust_cargo_default_feature_behavior')
|
||||
if l:default_feature_behavior is# 'all'
|
||||
let l:include_features = ''
|
||||
let l:default_feature = ' --all-features'
|
||||
elseif l:default_feature_behavior is# 'none'
|
||||
let l:default_feature = ' --no-default-features'
|
||||
else
|
||||
let l:default_feature = ''
|
||||
endif
|
||||
|
||||
return 'cargo '
|
||||
\ . (l:use_check ? 'check' : 'build')
|
||||
\ . (l:use_all_targets ? ' --all-targets' : '')
|
||||
\ . ' --frozen --message-format=json -q'
|
||||
\ . l:default_feature
|
||||
\ . l:include_features
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('rust', {
|
||||
\ 'name': 'cargo',
|
||||
\ 'executable_callback': 'ale_linters#rust#cargo#GetCargoExecutable',
|
||||
\ 'command_chain': [
|
||||
\ {'callback': 'ale_linters#rust#cargo#VersionCheck'},
|
||||
\ {'callback': 'ale_linters#rust#cargo#GetCommand'},
|
||||
\ ],
|
||||
\ 'callback': 'ale#handlers#rust#HandleRustErrors',
|
||||
\ 'output_stream': 'both',
|
||||
\ 'lint_file': 1,
|
||||
\})
|
36
sources_non_forked/ale/ale_linters/rust/rls.vim
Normal file
36
sources_non_forked/ale/ale_linters/rust/rls.vim
Normal file
@ -0,0 +1,36 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: A language server for Rust
|
||||
|
||||
call ale#Set('rust_rls_executable', 'rls')
|
||||
call ale#Set('rust_rls_toolchain', 'nightly')
|
||||
|
||||
function! ale_linters#rust#rls#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'rust_rls_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#rust#rls#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#rust#rls#GetExecutable(a:buffer)
|
||||
let l:toolchain = ale#Var(a:buffer, 'rust_rls_toolchain')
|
||||
|
||||
return ale#Escape(l:executable)
|
||||
\ . ' +' . ale#Escape(l:toolchain)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#rust#rls#GetLanguage(buffer) abort
|
||||
return 'rust'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#rust#rls#GetProjectRoot(buffer) abort
|
||||
let l:cargo_file = ale#path#FindNearestFile(a:buffer, 'Cargo.toml')
|
||||
|
||||
return !empty(l:cargo_file) ? fnamemodify(l:cargo_file, ':h') : ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('rust', {
|
||||
\ 'name': 'rls',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable_callback': 'ale_linters#rust#rls#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#rust#rls#GetCommand',
|
||||
\ 'language_callback': 'ale_linters#rust#rls#GetLanguage',
|
||||
\ 'project_root_callback': 'ale_linters#rust#rls#GetProjectRoot',
|
||||
\})
|
33
sources_non_forked/ale/ale_linters/rust/rustc.vim
Normal file
33
sources_non_forked/ale/ale_linters/rust/rustc.vim
Normal file
@ -0,0 +1,33 @@
|
||||
" Author: Daniel Schemala <istjanichtzufassen@gmail.com>
|
||||
" Description: rustc for rust files
|
||||
|
||||
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, 'Cargo.toml')
|
||||
|
||||
if l:cargo_file isnot# ''
|
||||
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
|
||||
|
||||
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', {
|
||||
\ 'name': 'rustc',
|
||||
\ 'executable': 'rustc',
|
||||
\ 'command_callback': 'ale_linters#rust#rustc#RustcCommand',
|
||||
\ 'callback': 'ale#handlers#rust#HandleRustErrors',
|
||||
\ 'output_stream': 'stderr',
|
||||
\})
|
Reference in New Issue
Block a user