From f5c289dce68f1592281b5d70539df91d4b3d2821 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 16 Oct 2019 11:34:06 -0400 Subject: [PATCH 01/10] Add support for rust-analyzer Fixes #2832 --- ale_linters/rust/analyzer.vim | 24 +++++++++++++++++++ doc/ale-rust.txt | 24 +++++++++++++++++++ doc/ale.txt | 1 + supported-tools.md | 1 + .../test_rust_analyzer_callbacks.vader | 20 ++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 ale_linters/rust/analyzer.vim create mode 100644 test/command_callback/test_rust_analyzer_callbacks.vader 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 +" 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. @@ -190,6 +195,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'}} From 81cb40ce4ba5d7fac7ebd9456f1d06af7fd902a0 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 16 Oct 2019 11:54:43 -0400 Subject: [PATCH 02/10] minor test fix --- test/command_callback/test_rust_analyzer_callbacks.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/command_callback/test_rust_analyzer_callbacks.vader b/test/command_callback/test_rust_analyzer_callbacks.vader index 887cf127..55af405b 100644 --- a/test/command_callback/test_rust_analyzer_callbacks.vader +++ b/test/command_callback/test_rust_analyzer_callbacks.vader @@ -5,7 +5,7 @@ After: call ale#assert#TearDownLinterTest() Execute(The default executable path should be correct): - AssertLinter 'analyzer', ale#Escape('ra_lsp_server') + AssertLinter 'ra_lsp_server', ale#Escape('ra_lsp_server') Execute(The project root should be detected correctly): AssertLSPProject '' From d74db90550f061b3609bb9fe9a04b936b1a16a1d Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 16 Oct 2019 13:44:01 -0400 Subject: [PATCH 03/10] Make TOC match up --- doc/ale.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index e8716de1..28cb7907 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2411,7 +2411,7 @@ documented in additional help files. rust....................................|ale-rust-options| cargo.................................|ale-rust-cargo| rls...................................|ale-rust-rls| - rust-analyzer.........................|ale-rust-analyzer| + analyzer..............................|ale-rust-analyzer| rustc.................................|ale-rust-rustc| rustfmt...............................|ale-rust-rustfmt| sass....................................|ale-sass-options| From 29d0987859695b60c3515feb45ff45ef6443d5ad Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 16 Oct 2019 14:01:57 -0400 Subject: [PATCH 04/10] Fix TOC sorting --- doc/ale.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index 28cb7907..01b8f858 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2409,9 +2409,9 @@ 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| - analyzer..............................|ale-rust-analyzer| rustc.................................|ale-rust-rustc| rustfmt...............................|ale-rust-rustfmt| sass....................................|ale-sass-options| From 4b53d88cb83951cfd6b246dcf5d7ba0ad2b56d14 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 16 Oct 2019 14:03:10 -0400 Subject: [PATCH 05/10] Also list analyzer in doc/ supported tools --- doc/ale-supported-languages-and-tools.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index a5b7c35e..2076617b 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -404,6 +404,7 @@ Notes: * Rust * `cargo`!! * `rls` + * `rust-analyzer` * `rustc` (see |ale-integration-rust|) * `rustfmt` * Sass From fedd3de59f3bea1ecb202250fc1d67a66b0a708f Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 16 Oct 2019 14:41:04 -0400 Subject: [PATCH 06/10] Place rust sections in alphabetical order --- doc/ale-rust.txt | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt index 05390225..b4efbb1b 100644 --- a/doc/ale-rust.txt +++ b/doc/ale-rust.txt @@ -41,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: `'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. + =============================================================================== cargo *ale-rust-cargo* @@ -195,25 +214,6 @@ 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* From 9c797961faf8360edf27b40aa7d53a6f9aa0e993 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Oct 2019 12:01:31 -0400 Subject: [PATCH 07/10] Make more names match up --- ale_linters/rust/analyzer.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/rust/analyzer.vim b/ale_linters/rust/analyzer.vim index 54a7cb1c..b964e4a2 100644 --- a/ale_linters/rust/analyzer.vim +++ b/ale_linters/rust/analyzer.vim @@ -15,7 +15,7 @@ function! ale_linters#rust#analyzer#GetProjectRoot(buffer) abort endfunction call ale#linter#Define('rust', { -\ 'name': 'rust-analyzer', +\ 'name': 'analyzer', \ 'lsp': 'stdio', \ 'lsp_config': {b -> ale#Var(b, 'rust_analyzer_config')}, \ 'executable': {b -> ale#Var(b, 'rust_analyzer_executable')}, From 715733f44def5e162d90184ae12886c54adeeb5b Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 11 Dec 2019 12:01:28 -0500 Subject: [PATCH 08/10] Fix Rust linter/fixer listing --- doc/ale-rust.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt index b4efbb1b..2e0f3474 100644 --- a/doc/ale-rust.txt +++ b/doc/ale-rust.txt @@ -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,12 +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. - 3. analyzer -- If you have rust-analyzer installed, you might prefer using + 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. - 4. rustfmt -- If you have `rustfmt` installed, you can use it as a fixer to + 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, From 58404b5b83ff08dd32b93cae57c2bae088a989e0 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 9 Apr 2020 08:57:02 -0400 Subject: [PATCH 09/10] rust-analyzer server binary changed name --- ale_linters/rust/analyzer.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/rust/analyzer.vim b/ale_linters/rust/analyzer.vim index b964e4a2..3666ec03 100644 --- a/ale_linters/rust/analyzer.vim +++ b/ale_linters/rust/analyzer.vim @@ -1,7 +1,7 @@ " Author: Jon Gjengset " Description: The next generation language server for Rust -call ale#Set('rust_analyzer_executable', 'ra_lsp_server') +call ale#Set('rust_analyzer_executable', 'rust-analyzer') call ale#Set('rust_analyzer_config', {}) function! ale_linters#rust#analyzer#GetCommand(buffer) abort From 6087765cad9271a54d3a29c0c0e6582332461451 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 9 Apr 2020 13:23:03 -0400 Subject: [PATCH 10/10] Move to rust-analyzer everywhere --- doc/ale-rust.txt | 2 +- test/command_callback/test_rust_analyzer_callbacks.vader | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt index 2e0f3474..46d4714b 100644 --- a/doc/ale-rust.txt +++ b/doc/ale-rust.txt @@ -47,7 +47,7 @@ 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'` + Default: `'rust-analyzer'` This variable can be modified to change the executable path for `rust-analyzer`. diff --git a/test/command_callback/test_rust_analyzer_callbacks.vader b/test/command_callback/test_rust_analyzer_callbacks.vader index 55af405b..95866076 100644 --- a/test/command_callback/test_rust_analyzer_callbacks.vader +++ b/test/command_callback/test_rust_analyzer_callbacks.vader @@ -5,7 +5,7 @@ After: call ale#assert#TearDownLinterTest() Execute(The default executable path should be correct): - AssertLinter 'ra_lsp_server', ale#Escape('ra_lsp_server') + AssertLinter 'rust-analyzer', ale#Escape('rust-analyzer') Execute(The project root should be detected correctly): AssertLSPProject ''