From 655dd188d6b8b43e4f3b1a7e3503af77d25bea63 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Sat, 8 Jul 2023 11:59:46 +0200 Subject: [PATCH 1/3] Remind user to check $PATH after installation. --- docs/user/manual.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index bd924031e03..bcaebd87c79 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -141,6 +141,8 @@ If you're not using Code, you can compile and install only the LSP server: $ cargo xtask install --server ---- +Make sure that `.cargo/bin` is in `$PATH` and precedes paths where `rust-analyzer` may also be installed. + === rust-analyzer Language Server Binary Other editors generally require the `rust-analyzer` binary to be in `$PATH`. From 9200d27a263c243a3073d7b30ae7f677048e2117 Mon Sep 17 00:00:00 2001 From: Omer Tuchfeld Date: Sat, 8 Jul 2023 13:48:04 +0200 Subject: [PATCH 2/3] Stop inserting semicolon when extracting match arm # Overview Extracting a match arm value that has type unit into a function, when a comma already follows the match arm value, results in an invalid (syntax error) semicolon added between the newly generated function's generated call and the comma. # Example Running this extraction ```rust fn main() { match () { _ => $0()$0, }; } ``` would lead to ```rust fn main() { match () { _ => fun_name();, }; } fn fun_name() { } ``` # Issue / Fix details This happens because when there is no comma, rust-analyzer would simply add the comma and wouldn't even try to evaluate whether it needs to add a semicolon. But when the comma is there, it proceeds to evaluate whether it needs to add a semicolon and it looks like the evaluation logic erroneously ignores the possibility that we're in a match arm. IIUC it never makes sense to add a semicolon when we're extracting from a match arm value, so I've adjusted the logic to always decide against adding a semicolon when we're in a match arm --- .../src/handlers/extract_function.rs | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs index 2a67909e637..e9db38aca0f 100644 --- a/crates/ide-assists/src/handlers/extract_function.rs +++ b/crates/ide-assists/src/handlers/extract_function.rs @@ -1360,14 +1360,15 @@ fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> St } format_to!(buf, "{expr}"); - let insert_comma = fun - .body - .parent() - .and_then(ast::MatchArm::cast) - .map_or(false, |it| it.comma_token().is_none()); + let parent_match_arm = fun.body.parent().and_then(ast::MatchArm::cast); + let insert_comma = parent_match_arm.as_ref().is_some_and(|it| it.comma_token().is_none()); + if insert_comma { buf.push(','); - } else if fun.ret_ty.is_unit() && (!fun.outliving_locals.is_empty() || !expr.is_block_like()) { + } else if parent_match_arm.is_none() + && fun.ret_ty.is_unit() + && (!fun.outliving_locals.is_empty() || !expr.is_block_like()) + { buf.push(';'); } buf @@ -4611,6 +4612,29 @@ fn $0fun_name() -> i32 { } "#, ); + + // Makes sure no semicolon is added for unit-valued match arms + check_assist( + extract_function, + r#" +fn main() { + match () { + _ => $0()$0, + } +} +"#, + r#" +fn main() { + match () { + _ => fun_name(), + } +} + +fn $0fun_name() { + () +} +"#, + ) } #[test] From 2e5d431dfcb5402e438c71a28895f9def0084129 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Sat, 8 Jul 2023 16:15:08 +0200 Subject: [PATCH 3/3] Update docs/user/manual.adoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laurențiu Nicola --- docs/user/manual.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index bcaebd87c79..b23c7c35d5d 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -142,6 +142,7 @@ $ cargo xtask install --server ---- Make sure that `.cargo/bin` is in `$PATH` and precedes paths where `rust-analyzer` may also be installed. +Specifically, `rustup` includes a proxy called `rust-analyzer`, which can cause problems if you're planning to use a source build or even a downloaded binary. === rust-analyzer Language Server Binary