mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 13:34:46 +08:00
Merge branch 'rust-analyzer' of https://github.com/jonhoo/ale into jonhoo-rust-analyzer
This commit is contained in:
24
ale_linters/rust/analyzer.vim
Normal file
24
ale_linters/rust/analyzer.vim
Normal 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'),
|
||||||
|
\})
|
||||||
@@ -9,7 +9,7 @@ Integration Information
|
|||||||
files for Rust distributed in Vim >=8.0.0501 or upstream:
|
files for Rust distributed in Vim >=8.0.0501 or upstream:
|
||||||
https://github.com/rust-lang/rust.vim
|
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.
|
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
|
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
|
over cargo. rls implements the Language Server Protocol for incremental
|
||||||
compilation of Rust code, and can check Rust files while you type. `rls`
|
compilation of Rust code, and can check Rust files while you type. `rls`
|
||||||
requires Rust files to contained in Cargo projects.
|
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.
|
consistently reformat your Rust code.
|
||||||
|
|
||||||
Only cargo is enabled by default. To switch to using rustc instead of cargo,
|
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.
|
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*
|
cargo *ale-rust-cargo*
|
||||||
|
|
||||||
|
|||||||
@@ -408,6 +408,7 @@ Notes:
|
|||||||
* Rust
|
* Rust
|
||||||
* `cargo`!!
|
* `cargo`!!
|
||||||
* `rls`
|
* `rls`
|
||||||
|
* `rust-analyzer`
|
||||||
* `rustc` (see |ale-integration-rust|)
|
* `rustc` (see |ale-integration-rust|)
|
||||||
* `rustfmt`
|
* `rustfmt`
|
||||||
* Sass
|
* Sass
|
||||||
|
|||||||
@@ -2579,6 +2579,7 @@ documented in additional help files.
|
|||||||
sorbet................................|ale-ruby-sorbet|
|
sorbet................................|ale-ruby-sorbet|
|
||||||
standardrb............................|ale-ruby-standardrb|
|
standardrb............................|ale-ruby-standardrb|
|
||||||
rust....................................|ale-rust-options|
|
rust....................................|ale-rust-options|
|
||||||
|
analyzer..............................|ale-rust-analyzer|
|
||||||
cargo.................................|ale-rust-cargo|
|
cargo.................................|ale-rust-cargo|
|
||||||
rls...................................|ale-rust-rls|
|
rls...................................|ale-rust-rls|
|
||||||
rustc.................................|ale-rust-rustc|
|
rustc.................................|ale-rust-rustc|
|
||||||
|
|||||||
@@ -417,6 +417,7 @@ formatting.
|
|||||||
* Rust
|
* Rust
|
||||||
* [cargo](https://github.com/rust-lang/cargo) :floppy_disk: (see `:help ale-integration-rust` for configuration instructions)
|
* [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:
|
* [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:
|
* [rustc](https://www.rust-lang.org/) :warning:
|
||||||
* [rustfmt](https://github.com/rust-lang-nursery/rustfmt)
|
* [rustfmt](https://github.com/rust-lang-nursery/rustfmt)
|
||||||
* Sass
|
* Sass
|
||||||
|
|||||||
20
test/command_callback/test_rust_analyzer_callbacks.vader
Normal file
20
test/command_callback/test_rust_analyzer_callbacks.vader
Normal 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'}}
|
||||||
Reference in New Issue
Block a user