Skip to content

Commit 5f8cfeb

Browse files
committed
fix: convert_integer_literal not on selected
`convert_integer_literal` can only convert the first literal, it is not reasonable to apply it when selected Example --- ```rust fn main() { $01+1$0; } ``` **Assist old outputs**: ``` Convert 1 to 0b1 Convert 1 to 0o1 Convert 1 to 0x1 Replace arithmetic with call to checked_* Replace arithmetic with call to saturating_* Replace arithmetic with call to wrapping_* Extract into variable Extract into constant Extract into static Extract into function ``` **Assist this PR outputs**: ``` Replace arithmetic with call to checked_* Replace arithmetic with call to saturating_* Replace arithmetic with call to wrapping_* Extract into variable Extract into constant Extract into static Extract into function ```
1 parent e10fa93 commit 5f8cfeb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/ide-assists/src/handlers/convert_integer_literal.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use crate::{AssistContext, AssistId, Assists, GroupLabel};
1414
// const _: i32 = 0b1010;
1515
// ```
1616
pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
17+
if !ctx.has_empty_selection() {
18+
return None;
19+
}
1720
let literal = ctx.find_node_at_offset::<ast::Literal>()?;
1821
let literal = match literal.kind() {
1922
ast::LiteralKind::IntNumber(it) => it,
@@ -265,4 +268,9 @@ mod tests {
265268
111111111111111111111111111111111111111111111111111111111111111111111111$0;";
266269
check_assist_not_applicable(convert_integer_literal, before);
267270
}
271+
272+
#[test]
273+
fn convert_non_empty_selection_literal() {
274+
check_assist_not_applicable(convert_integer_literal, "const _: i32 = $00b1010$0;");
275+
}
268276
}

crates/ide-assists/src/tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ pub fn test_some_range(a: int) -> bool {
456456
let expected = labels(&assists);
457457

458458
expect![[r#"
459-
Convert integer base
460459
Extract into...
461460
Replace if let with match
462461
"#]]
@@ -489,7 +488,6 @@ pub fn test_some_range(a: int) -> bool {
489488
let expected = labels(&assists);
490489

491490
expect![[r#"
492-
Convert integer base
493491
Extract into...
494492
Replace if let with match
495493
"#]]

0 commit comments

Comments
 (0)