diff options
| author | A4-Tacks <wdsjxhno1001@163.com> | 2025-08-22 17:31:55 +0800 |
|---|---|---|
| committer | A4-Tacks <wdsjxhno1001@163.com> | 2025-08-24 07:57:50 +0800 |
| commit | 5e81912dae790647395834a027263a8c6160fd0b (patch) | |
| tree | 8bdbfe8b5b7377298822200a31f6ba01d0e53646 /src/tools/rust-analyzer | |
| parent | 8e7cca83344e511e263e91f9539b8d341b2dd2bb (diff) | |
replace_arith_op not applicable on selected
Diffstat (limited to 'src/tools/rust-analyzer')
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_arith_op.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_arith_op.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_arith_op.rs index 6b385a03625..440ab4d4604 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_arith_op.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_arith_op.rs @@ -102,6 +102,9 @@ fn is_primitive_int(ctx: &AssistContext<'_>, expr: &ast::Expr) -> bool { /// Extract the operands of an arithmetic expression (e.g. `1 + 2` or `1.checked_add(2)`) fn parse_binary_op(ctx: &AssistContext<'_>) -> Option<(ast::Expr, ArithOp, ast::Expr)> { + if !ctx.has_empty_selection() { + return None; + } let expr = ctx.find_node_at_offset::<ast::BinExpr>()?; let op = match expr.op_kind() { @@ -163,7 +166,7 @@ impl ArithKind { #[cfg(test)] mod tests { - use crate::tests::check_assist; + use crate::tests::{check_assist, check_assist_not_applicable}; use super::*; @@ -223,4 +226,16 @@ fn main() { "#, ) } + + #[test] + fn replace_arith_not_applicable_with_non_empty_selection() { + check_assist_not_applicable( + replace_arith_with_checked, + r#" +fn main() { + let x = 1 $0+$0 2; +} +"#, + ) + } } |
