From 735aaa7b39b4d3d789ad75c167bbf322a65ca257 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Nov 2020 18:54:01 +0100 Subject: Move int parsing to IntNumber token --- crates/assists/src/handlers/convert_integer_literal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/convert_integer_literal.rs b/crates/assists/src/handlers/convert_integer_literal.rs index c8af80701..6d477c045 100644 --- a/crates/assists/src/handlers/convert_integer_literal.rs +++ b/crates/assists/src/handlers/convert_integer_literal.rs @@ -15,7 +15,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; // ``` pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let literal = ctx.find_node_at_offset::()?; - let (radix, value) = literal.int_value()?; + let (radix, value) = literal.as_int_number()?.value()?; let range = literal.syntax().text_range(); let group_id = GroupLabel("Convert integer base".into()); -- cgit v1.2.3 From eb460333907a44c37bf7287b31c653877c3358c2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Nov 2020 19:01:25 +0100 Subject: More orthogonal API --- .../src/handlers/convert_integer_literal.rs | 23 ++++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/convert_integer_literal.rs b/crates/assists/src/handlers/convert_integer_literal.rs index 6d477c045..5957834d3 100644 --- a/crates/assists/src/handlers/convert_integer_literal.rs +++ b/crates/assists/src/handlers/convert_integer_literal.rs @@ -1,4 +1,4 @@ -use syntax::{ast, ast::Radix, AstNode}; +use syntax::{ast, ast::Radix, AstToken}; use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; @@ -14,15 +14,13 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; // const _: i32 = 0b1010; // ``` pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let literal = ctx.find_node_at_offset::()?; - let (radix, value) = literal.as_int_number()?.value()?; + let literal = ctx.find_node_at_offset::()?.as_int_number()?; + let radix = literal.radix(); + let value = literal.value()?; + let suffix = literal.suffix(); let range = literal.syntax().text_range(); let group_id = GroupLabel("Convert integer base".into()); - let suffix = match literal.kind() { - ast::LiteralKind::IntNumber { suffix } => suffix, - _ => return None, - }; for &target_radix in Radix::ALL { if target_radix == radix { @@ -36,16 +34,11 @@ pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext) -> Radix::Hexadecimal => format!("0x{:X}", value), }; - let label = format!( - "Convert {} to {}{}", - literal, - converted, - suffix.as_deref().unwrap_or_default() - ); + let label = format!("Convert {} to {}{}", literal, converted, suffix.unwrap_or_default()); // Appends the type suffix back into the new literal if it exists. - if let Some(suffix) = &suffix { - converted.push_str(&suffix); + if let Some(suffix) = suffix { + converted.push_str(suffix); } acc.add_group( -- cgit v1.2.3