Merge branch 'rust-analyzer' of https://github.com/jonhoo/ale into jonhoo-rust-analyzer

This commit is contained in:
RyanSquared 2020-05-05 09:21:49 -05:00
commit 70005134e5
No known key found for this signature in database
GPG Key ID: 6785F7AF28DE7081
6 changed files with 73 additions and 2 deletions

View File

@ -0,0 +1,24 @@
" Author: Jon Gjengset <jon@thesquareplanet.com>
" Description: The next generation language server for Rust
call ale#Set('rust_analyzer_executable', 'rust-analyzer')
call ale#Set('rust_analyzer_config', {})
function! ale_linters#rust#analyzer#GetCommand(buffer) abort
return '%e'
endfunction
function! ale_linters#rust#analyzer#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': 'analyzer',
\ 'lsp': 'stdio',
\ 'lsp_config': {b -> ale#Var(b, 'rust_analyzer_config')},
\ 'executable': {b -> ale#Var(b, 'rust_analyzer_executable')},
\ 'command': function('ale_linters#rust#analyzer#GetCommand'),
\ 'project_root': function('ale_linters#rust#analyzer#GetProjectRoot'),
\})

View File

@ -9,7 +9,7 @@ Integration Information
files for Rust distributed in Vim >=8.0.0501 or upstream:
https://github.com/rust-lang/rust.vim
Note that there are three possible linters for Rust files:
Note that there are several possible linters and fixers for Rust files:
1. rustc -- The Rust compiler is used to check the currently edited file.
So, if your project consists of multiple files, you will get some errors
@ -23,7 +23,12 @@ Integration Information
over cargo. rls implements the Language Server Protocol for incremental
compilation of Rust code, and can check Rust files while you type. `rls`
requires Rust files to contained in Cargo projects.
4. rustfmt -- If you have `rustfmt` installed, you can use it as a fixer to
4. analyzer -- If you have rust-analyzer installed, you might prefer using
this linter over cargo and rls. rust-analyzer also implements the
Language Server Protocol for incremental compilation of Rust code, and is
the next iteration of rls. rust-analyzer, like rls, requires Rust files
to contained in Cargo projects.
5. rustfmt -- If you have `rustfmt` installed, you can use it as a fixer to
consistently reformat your Rust code.
Only cargo is enabled by default. To switch to using rustc instead of cargo,
@ -36,6 +41,25 @@ Integration Information
Also note that rustc 1.12. or later is needed.
===============================================================================
analyzer *ale-rust-analyzer*
g:ale_rust_analyzer_executable *g:ale_rust_analyzer_executable*
*b:ale_rust_analyzer_executable*
Type: |String|
Default: `'rust-analyzer'`
This variable can be modified to change the executable path for
`rust-analyzer`.
g:ale_rust_analyzer_config *g:ale_rust_analyzer_config*
*b:ale_rust_analyzer_config*
Type: |Dictionary|
Default: `{}`
Dictionary with configuration settings for rust-analyzer.
===============================================================================
cargo *ale-rust-cargo*

View File

@ -408,6 +408,7 @@ Notes:
* Rust
* `cargo`!!
* `rls`
* `rust-analyzer`
* `rustc` (see |ale-integration-rust|)
* `rustfmt`
* Sass

View File

@ -2579,6 +2579,7 @@ documented in additional help files.
sorbet................................|ale-ruby-sorbet|
standardrb............................|ale-ruby-standardrb|
rust....................................|ale-rust-options|
analyzer..............................|ale-rust-analyzer|
cargo.................................|ale-rust-cargo|
rls...................................|ale-rust-rls|
rustc.................................|ale-rust-rustc|

View File

@ -417,6 +417,7 @@ formatting.
* Rust
* [cargo](https://github.com/rust-lang/cargo) :floppy_disk: (see `:help ale-integration-rust` for configuration instructions)
* [rls](https://github.com/rust-lang-nursery/rls) :warning:
* [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer) :warning:
* [rustc](https://www.rust-lang.org/) :warning:
* [rustfmt](https://github.com/rust-lang-nursery/rustfmt)
* Sass

View File

@ -0,0 +1,20 @@
Before:
call ale#assert#SetUpLinterTest('rust', 'analyzer')
After:
call ale#assert#TearDownLinterTest()
Execute(The default executable path should be correct):
AssertLinter 'rust-analyzer', ale#Escape('rust-analyzer')
Execute(The project root should be detected correctly):
AssertLSPProject ''
call ale#test#SetFilename('rust-rls-project/test.rs')
AssertLSPProject ale#path#Simplify(g:dir . '/rust-rls-project')
Execute(Should accept configuration settings):
AssertLSPConfig {}
let b:ale_rust_analyzer_config = {'rust': {'clippy_preference': 'on'}}
AssertLSPConfig {'rust': {'clippy_preference': 'on'}}