diff options
author | Jon Gjengset <jon@thesquareplanet.com> | 2019-10-16 11:34:06 -0400 |
---|---|---|
committer | Jon Gjengset <jon@thesquareplanet.com> | 2019-10-16 11:34:16 -0400 |
commit | f5c289dce68f1592281b5d70539df91d4b3d2821 (patch) | |
tree | 186a245ea37232eed48c3654491ac5122a4e4401 | |
parent | 7c5825ecbc166d71976d01213e42723128d933e7 (diff) | |
download | ale-f5c289dce68f1592281b5d70539df91d4b3d2821.zip |
Add support for rust-analyzer
Fixes #2832
-rw-r--r-- | ale_linters/rust/analyzer.vim | 24 | ||||
-rw-r--r-- | doc/ale-rust.txt | 24 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/command_callback/test_rust_analyzer_callbacks.vader | 20 |
5 files changed, 70 insertions, 0 deletions
diff --git a/ale_linters/rust/analyzer.vim b/ale_linters/rust/analyzer.vim new file mode 100644 index 00000000..54a7cb1c --- /dev/null +++ b/ale_linters/rust/analyzer.vim @@ -0,0 +1,24 @@ +" Author: Jon Gjengset <jon@thesquareplanet.com> +" Description: The next generation language server for Rust + +call ale#Set('rust_analyzer_executable', 'ra_lsp_server') +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': 'rust-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'), +\}) diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt index 44a79b18..05390225 100644 --- a/doc/ale-rust.txt +++ b/doc/ale-rust.txt @@ -23,6 +23,11 @@ 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. + 3. 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. 4. rustfmt -- If you have `rustfmt` installed, you can use it as a fixer to consistently reformat your Rust code. @@ -191,6 +196,25 @@ g:ale_rust_rls_config *g:ale_rust_rls_config* =============================================================================== +analyzer *ale-rust-analyzer* + +g:ale_rust_analyzer_executable *g:ale_rust_analyzer_executable* + *b:ale_rust_analyzer_executable* + Type: |String| + Default: `'ra_lsp_server'` + + 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. + +=============================================================================== rustc *ale-rust-rustc* diff --git a/doc/ale.txt b/doc/ale.txt index 01b6181d..e8716de1 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2411,6 +2411,7 @@ documented in additional help files. rust....................................|ale-rust-options| cargo.................................|ale-rust-cargo| rls...................................|ale-rust-rls| + rust-analyzer.........................|ale-rust-analyzer| rustc.................................|ale-rust-rustc| rustfmt...............................|ale-rust-rustfmt| sass....................................|ale-sass-options| diff --git a/supported-tools.md b/supported-tools.md index 226baeaf..90dd719f 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -413,6 +413,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 diff --git a/test/command_callback/test_rust_analyzer_callbacks.vader b/test/command_callback/test_rust_analyzer_callbacks.vader new file mode 100644 index 00000000..887cf127 --- /dev/null +++ b/test/command_callback/test_rust_analyzer_callbacks.vader @@ -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 'analyzer', ale#Escape('ra_lsp_server') + +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'}} |