From b1d5817dd18b7b5fc102a63b084b1ee7ff4f9996 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 23:40:41 +0200 Subject: Convert code to text-size --- crates/ra_assists/src/assist_ctx.rs | 8 ++++---- crates/ra_assists/src/handlers/add_custom_impl.rs | 8 ++++---- crates/ra_assists/src/handlers/add_derive.rs | 8 ++++---- crates/ra_assists/src/handlers/add_explicit_type.rs | 4 ++-- crates/ra_assists/src/handlers/add_from_impl_for_enum.rs | 4 ++-- crates/ra_assists/src/handlers/add_function.rs | 8 ++++---- crates/ra_assists/src/handlers/add_impl.rs | 4 ++-- crates/ra_assists/src/handlers/add_new.rs | 8 ++++---- crates/ra_assists/src/handlers/apply_demorgan.rs | 2 +- crates/ra_assists/src/handlers/change_visibility.rs | 4 ++-- crates/ra_assists/src/handlers/flip_binexpr.rs | 2 +- crates/ra_assists/src/handlers/inline_local_variable.rs | 2 +- crates/ra_assists/src/handlers/introduce_variable.rs | 6 +++--- crates/ra_assists/src/handlers/invert_if.rs | 2 +- crates/ra_assists/src/handlers/merge_match_arms.rs | 10 +++++----- crates/ra_assists/src/handlers/move_guard.rs | 10 +++++----- crates/ra_assists/src/handlers/raw_string.rs | 4 ++-- crates/ra_assists/src/handlers/remove_dbg.rs | 8 ++++---- crates/ra_assists/src/handlers/remove_mut.rs | 2 +- .../ra_assists/src/handlers/replace_qualified_name_with_use.rs | 2 +- crates/ra_assists/src/lib.rs | 6 +++--- 21 files changed, 56 insertions(+), 56 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 279163257..2fe7c3de3 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -5,7 +5,7 @@ use ra_fmt::{leading_indent, reindent}; use ra_ide_db::RootDatabase; use ra_syntax::{ algo::{self, find_covering_element, find_node_at_offset}, - AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit, + AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, }; use ra_text_edit::TextEditBuilder; @@ -178,7 +178,7 @@ impl<'a> AssistGroup<'a> { #[derive(Default)] pub(crate) struct ActionBuilder { edit: TextEditBuilder, - cursor_position: Option, + cursor_position: Option, target: Option, file: AssistFile, } @@ -211,12 +211,12 @@ impl ActionBuilder { } /// Append specified `text` at the given `offset` - pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into) { + pub(crate) fn insert(&mut self, offset: TextSize, text: impl Into) { self.edit.insert(offset, text.into()) } /// Specify desired position of the cursor after the assist is applied. - pub(crate) fn set_cursor(&mut self, offset: TextUnit) { + pub(crate) fn set_cursor(&mut self, offset: TextSize) { self.cursor_position = Some(offset) } diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 15f9b216b..7bb90dba3 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -2,7 +2,7 @@ use ra_syntax::{ ast::{self, AstNode}, Direction, SmolStr, SyntaxKind::{IDENT, WHITESPACE}, - TextRange, TextUnit, + TextRange, TextSize, }; use stdx::SepBy; @@ -71,7 +71,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { let cursor_delta = if has_more_derives { edit.replace(input.syntax().text_range(), new_attr_input); - input.syntax().text_range().len() - TextUnit::from_usize(new_attr_input_len) + input.syntax().text_range().len() - TextSize::from_usize(new_attr_input_len) } else { let attr_range = attr.syntax().text_range(); edit.delete(attr_range); @@ -81,13 +81,13 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { .next_sibling_or_token() .filter(|t| t.kind() == WHITESPACE) .map(|t| t.text_range()) - .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); + .unwrap_or_else(|| TextRange::new(TextSize::from(0), TextSize::from(0))); edit.delete(line_break_range); attr_range.len() + line_break_range.len() }; - edit.set_cursor(start_offset + TextUnit::of_str(&buf) - cursor_delta); + edit.set_cursor(start_offset + TextSize::of(&buf) - cursor_delta); buf.push_str("\n}"); edit.insert(start_offset, buf); }) diff --git a/crates/ra_assists/src/handlers/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs index b0d1a0a80..6254eb7c4 100644 --- a/crates/ra_assists/src/handlers/add_derive.rs +++ b/crates/ra_assists/src/handlers/add_derive.rs @@ -1,7 +1,7 @@ use ra_syntax::{ ast::{self, AstNode, AttrsOwner}, SyntaxKind::{COMMENT, WHITESPACE}, - TextUnit, + TextSize, }; use crate::{Assist, AssistCtx, AssistId}; @@ -37,9 +37,9 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option { let offset = match derive_attr { None => { edit.insert(node_start, "#[derive()]\n"); - node_start + TextUnit::of_str("#[derive(") + node_start + TextSize::of("#[derive(") } - Some(tt) => tt.syntax().text_range().end() - TextUnit::of_char(')'), + Some(tt) => tt.syntax().text_range().end() - TextSize::of(')'), }; edit.target(nominal.syntax().text_range()); edit.set_cursor(offset) @@ -47,7 +47,7 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option { } // Insert `derive` after doc comments. -fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option { +fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option { let non_ws_child = nominal .syntax() .children_with_tokens() diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs index 6c56d93d8..bc313782b 100644 --- a/crates/ra_assists/src/handlers/add_explicit_type.rs +++ b/crates/ra_assists/src/handlers/add_explicit_type.rs @@ -37,8 +37,8 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option { let stmt_range = stmt.syntax().text_range(); let eq_range = stmt.eq_token()?.text_range(); // Assist should only be applicable if cursor is between 'let' and '=' - let let_range = TextRange::from_to(stmt_range.start(), eq_range.start()); - let cursor_in_range = ctx.frange.range.is_subrange(&let_range); + let let_range = TextRange::new(stmt_range.start(), eq_range.start()); + let cursor_in_range = let_range.contains_range(ctx.frange.range); if !cursor_in_range { return None; } diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs index 0621487e8..03806724a 100644 --- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs @@ -1,6 +1,6 @@ use ra_syntax::{ ast::{self, AstNode, NameOwner}, - TextUnit, + TextSize, }; use stdx::format_to; @@ -65,7 +65,7 @@ impl From<{0}> for {1} {{ variant_name ); edit.insert(start_offset, buf); - edit.set_cursor(start_offset + TextUnit::of_str("\n\n")); + edit.set_cursor(start_offset + TextSize::of("\n\n")); }, ) } diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index f185cffdb..7a8f5705f 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -1,6 +1,6 @@ use ra_syntax::{ ast::{self, AstNode}, - SyntaxKind, SyntaxNode, TextUnit, + SyntaxKind, SyntaxNode, TextSize, }; use crate::{Assist, AssistCtx, AssistFile, AssistId}; @@ -69,8 +69,8 @@ pub(crate) fn add_function(ctx: AssistCtx) -> Option { } struct FunctionTemplate { - insert_offset: TextUnit, - cursor_offset: TextUnit, + insert_offset: TextSize, + cursor_offset: TextSize, fn_def: ast::SourceFile, file: AssistFile, } @@ -129,7 +129,7 @@ impl FunctionBuilder { let fn_def = indent_once.increase_indent(fn_def); let fn_def = ast::make::add_trailing_newlines(1, fn_def); let fn_def = indent.increase_indent(fn_def); - (fn_def, it.syntax().text_range().start() + TextUnit::from_usize(1)) + (fn_def, it.syntax().text_range().start() + TextSize::from_usize(1)) } }; diff --git a/crates/ra_assists/src/handlers/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs index 6622eadb2..d26f8b93d 100644 --- a/crates/ra_assists/src/handlers/add_impl.rs +++ b/crates/ra_assists/src/handlers/add_impl.rs @@ -1,6 +1,6 @@ use ra_syntax::{ ast::{self, AstNode, NameOwner, TypeParamsOwner}, - TextUnit, + TextSize, }; use stdx::{format_to, SepBy}; @@ -51,7 +51,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option { format_to!(buf, "<{}>", generic_params) } buf.push_str(" {\n"); - edit.set_cursor(start_offset + TextUnit::of_str(&buf)); + edit.set_cursor(start_offset + TextSize::of(&buf)); buf.push_str("\n}"); edit.insert(start_offset, buf); }) diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 240b19fa3..0698cce88 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -3,7 +3,7 @@ use ra_syntax::{ ast::{ self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner, }, - TextUnit, T, + TextSize, T, }; use stdx::{format_to, SepBy}; @@ -77,16 +77,16 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option { .text_range() .end(); - Some((start, TextUnit::from_usize(1))) + Some((start, TextSize::from_usize(1))) }) .unwrap_or_else(|| { buf = generate_impl_text(&strukt, &buf); let start = strukt.syntax().text_range().end(); - (start, TextUnit::from_usize(3)) + (start, TextSize::from_usize(3)) }); - edit.set_cursor(start_offset + TextUnit::of_str(&buf) - end_offset); + edit.set_cursor(start_offset + TextSize::of(&buf) - end_offset); edit.insert(start_offset, buf); }) } diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs index 239807e24..260b9e073 100644 --- a/crates/ra_assists/src/handlers/apply_demorgan.rs +++ b/crates/ra_assists/src/handlers/apply_demorgan.rs @@ -26,7 +26,7 @@ pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option { let op = expr.op_kind()?; let op_range = expr.op_token()?.text_range(); let opposite_op = opposite_logic_op(op)?; - let cursor_in_range = ctx.frange.range.is_subrange(&op_range); + let cursor_in_range = op_range.contains_range(ctx.frange.range); if !cursor_in_range { return None; } diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index cd6d1ee6c..44f6a1dae 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs @@ -5,7 +5,7 @@ use ra_syntax::{ ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY, WHITESPACE, }, - SyntaxNode, TextUnit, T, + SyntaxNode, TextSize, T, }; use crate::{Assist, AssistCtx, AssistId}; @@ -67,7 +67,7 @@ fn add_vis(ctx: AssistCtx) -> Option { }) } -fn vis_offset(node: &SyntaxNode) -> TextUnit { +fn vis_offset(node: &SyntaxNode) -> TextSize { node.children_with_tokens() .skip_while(|it| match it.kind() { WHITESPACE | COMMENT | ATTR => true, diff --git a/crates/ra_assists/src/handlers/flip_binexpr.rs b/crates/ra_assists/src/handlers/flip_binexpr.rs index bfcc09e90..8030efb35 100644 --- a/crates/ra_assists/src/handlers/flip_binexpr.rs +++ b/crates/ra_assists/src/handlers/flip_binexpr.rs @@ -23,7 +23,7 @@ pub(crate) fn flip_binexpr(ctx: AssistCtx) -> Option { let rhs = expr.rhs()?.syntax().clone(); let op_range = expr.op_token()?.text_range(); // The assist should be applied only if the cursor is on the operator - let cursor_in_range = ctx.frange.range.is_subrange(&op_range); + let cursor_in_range = op_range.contains_range(ctx.frange.range); if !cursor_in_range { return None; } diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index c4fb425b0..f5702f6e0 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs @@ -52,7 +52,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option { .next_sibling_or_token() .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone())) { - TextRange::from_to( + TextRange::new( let_stmt.syntax().text_range().start(), whitespace.syntax().text_range().end(), ) diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index 8c09e6bcd..eda9ac296 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs @@ -4,7 +4,7 @@ use ra_syntax::{ BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, WHITESPACE, }, - SyntaxNode, TextUnit, + SyntaxNode, TextSize, }; use stdx::format_to; use test_utils::tested_by; @@ -47,10 +47,10 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option { let cursor_offset = if wrap_in_block { buf.push_str("{ let var_name = "); - TextUnit::of_str("{ let ") + TextSize::of("{ let ") } else { buf.push_str("let var_name = "); - TextUnit::of_str("let ") + TextSize::of("let ") }; format_to!(buf, "{}", expr.syntax()); let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs index 4c5716868..682e08512 100644 --- a/crates/ra_assists/src/handlers/invert_if.rs +++ b/crates/ra_assists/src/handlers/invert_if.rs @@ -28,7 +28,7 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option { let if_keyword = ctx.find_token_at_offset(T![if])?; let expr = ast::IfExpr::cast(if_keyword.parent())?; let if_range = if_keyword.text_range(); - let cursor_in_range = ctx.frange.range.is_subrange(&if_range); + let cursor_in_range = if_range.contains_range(ctx.frange.range); if !cursor_in_range { return None; } diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index eb967ab92..cd0416f01 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs @@ -3,7 +3,7 @@ use std::iter::successors; use ra_syntax::{ algo::neighbor, ast::{self, AstNode}, - Direction, TextUnit, + Direction, TextSize, }; use crate::{Assist, AssistCtx, AssistId, TextRange}; @@ -42,8 +42,8 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { let current_text_range = current_arm.syntax().text_range(); enum CursorPos { - InExpr(TextUnit), - InPat(TextUnit), + InExpr(TextSize), + InPat(TextSize), } let cursor_pos = ctx.frange.range.start(); let cursor_pos = if current_expr.syntax().text_range().contains(cursor_pos) { @@ -89,10 +89,10 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { edit.target(current_text_range); edit.set_cursor(match cursor_pos { - CursorPos::InExpr(back_offset) => start + TextUnit::from_usize(arm.len()) - back_offset, + CursorPos::InExpr(back_offset) => start + TextSize::from_usize(arm.len()) - back_offset, CursorPos::InPat(offset) => offset, }); - edit.replace(TextRange::from_to(start, end), arm); + edit.replace(TextRange::new(start, end), arm); }) } diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs index 1cc498638..d5ccdd91c 100644 --- a/crates/ra_assists/src/handlers/move_guard.rs +++ b/crates/ra_assists/src/handlers/move_guard.rs @@ -1,7 +1,7 @@ use ra_syntax::{ ast, ast::{AstNode, AstToken, IfExpr, MatchArm}, - TextUnit, + TextSize, }; use crate::{Assist, AssistCtx, AssistId}; @@ -49,16 +49,16 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option { edit.delete(ele); ele.len() } else { - TextUnit::from(0) + TextSize::from(0) } } - _ => TextUnit::from(0), + _ => TextSize::from(0), }; edit.delete(guard.syntax().text_range()); edit.replace_node_and_indent(arm_expr.syntax(), buf); edit.set_cursor( - arm_expr.syntax().text_range().start() + TextUnit::from(3) - offseting_amount, + arm_expr.syntax().text_range().start() + TextSize::from(3) - offseting_amount, ); }) } @@ -123,7 +123,7 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option { } edit.insert(match_pat.syntax().text_range().end(), buf); - edit.set_cursor(match_pat.syntax().text_range().end() + TextUnit::from(1)); + edit.set_cursor(match_pat.syntax().text_range().end() + TextSize::from(1)); }, ) } diff --git a/crates/ra_assists/src/handlers/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs index 7e4b83f13..567400b9c 100644 --- a/crates/ra_assists/src/handlers/raw_string.rs +++ b/crates/ra_assists/src/handlers/raw_string.rs @@ -2,7 +2,7 @@ use ra_syntax::{ ast::{self, HasStringValue}, AstToken, SyntaxKind::{RAW_STRING, STRING}, - TextUnit, + TextSize, }; use crate::{Assist, AssistCtx, AssistId}; @@ -81,7 +81,7 @@ pub(crate) fn add_hash(ctx: AssistCtx) -> Option { let token = ctx.find_token_at_offset(RAW_STRING)?; ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| { edit.target(token.text_range()); - edit.insert(token.text_range().start() + TextUnit::of_char('r'), "#"); + edit.insert(token.text_range().start() + TextSize::of('r'), "#"); edit.insert(token.text_range().end(), "#"); }) } diff --git a/crates/ra_assists/src/handlers/remove_dbg.rs b/crates/ra_assists/src/handlers/remove_dbg.rs index 5085649b4..4e5eb4350 100644 --- a/crates/ra_assists/src/handlers/remove_dbg.rs +++ b/crates/ra_assists/src/handlers/remove_dbg.rs @@ -1,6 +1,6 @@ use ra_syntax::{ ast::{self, AstNode}, - TextUnit, T, + TextSize, T, }; use crate::{Assist, AssistCtx, AssistId}; @@ -38,9 +38,9 @@ pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option { let offset_start = file_range .start() .checked_sub(macro_range.start()) - .unwrap_or_else(|| TextUnit::from(0)); + .unwrap_or_else(|| TextSize::from(0)); - let dbg_size = TextUnit::of_str("dbg!("); + let dbg_size = TextSize::of("dbg!("); if offset_start > dbg_size { file_range.start() - dbg_size @@ -53,7 +53,7 @@ pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option { let macro_args = macro_call.token_tree()?.syntax().clone(); let text = macro_args.text(); - let without_parens = TextUnit::of_char('(')..text.len() - TextUnit::of_char(')'); + let without_parens = TextSize::of('(')..text.len() - TextSize::of(')'); text.slice(without_parens).to_string() }; diff --git a/crates/ra_assists/src/handlers/remove_mut.rs b/crates/ra_assists/src/handlers/remove_mut.rs index 6884830eb..e598023b2 100644 --- a/crates/ra_assists/src/handlers/remove_mut.rs +++ b/crates/ra_assists/src/handlers/remove_mut.rs @@ -27,6 +27,6 @@ pub(crate) fn remove_mut(ctx: AssistCtx) -> Option { ctx.add_assist(AssistId("remove_mut"), "Remove `mut` keyword", |edit| { edit.set_cursor(delete_from); - edit.delete(TextRange::from_to(delete_from, delete_to)); + edit.delete(TextRange::new(delete_from, delete_to)); }) } diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index 94f5d6c50..2f02df303 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs @@ -43,7 +43,7 @@ pub(crate) fn replace_qualified_name_with_use(ctx: AssistCtx) -> Option if let Some(last) = path.segment() { // Here we are assuming the assist will provide a correct use statement // so we can delete the path qualifier - edit.delete(TextRange::from_to( + edit.delete(TextRange::new( path.syntax().text_range().start(), last.syntax().text_range().start(), )); diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index ccc95735f..3ffbe4c51 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -19,7 +19,7 @@ pub mod ast_transform; use ra_db::{FileId, FileRange}; use ra_ide_db::RootDatabase; -use ra_syntax::{TextRange, TextUnit}; +use ra_syntax::{TextRange, TextSize}; use ra_text_edit::TextEdit; pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; @@ -51,7 +51,7 @@ impl AssistLabel { #[derive(Debug, Clone)] pub struct AssistAction { pub edit: TextEdit, - pub cursor_position: Option, + pub cursor_position: Option, // FIXME: This belongs to `AssistLabel` pub target: Option, pub file: AssistFile, @@ -104,7 +104,7 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec>(); - a.sort_by_key(|it| it.action.target.map_or(TextUnit::from(!0u32), |it| it.len())); + a.sort_by_key(|it| it.action.target.map_or(TextSize::from(!0u32), |it| it.len())); a } -- cgit v1.2.3 From 8843588fca7a6022b86800d5d2539594c0de93cf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 23:51:02 +0200 Subject: Convert tests to text-size --- crates/ra_assists/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 3ffbe4c51..64bd87afb 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -308,8 +308,7 @@ mod tests { let before = "struct Foo { <|>bar: u32 }"; let (before_cursor_pos, before) = extract_offset(before); let (db, file_id) = helpers::with_single_file(&before); - let frange = - FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; + let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; let assists = resolved_assists(&db, frange); let mut assists = assists.iter(); -- cgit v1.2.3 From 63a462f37ca584e1a585a69e30823ce25d4d252f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Apr 2020 00:57:47 +0200 Subject: Switch to TryFrom --- crates/ra_assists/src/handlers/add_custom_impl.rs | 4 ++-- crates/ra_assists/src/handlers/add_function.rs | 2 +- crates/ra_assists/src/handlers/add_new.rs | 4 ++-- crates/ra_assists/src/handlers/merge_match_arms.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 7bb90dba3..4ea26a550 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { .collect::>(); let has_more_derives = !new_attr_input.is_empty(); let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); - let new_attr_input_len = new_attr_input.len(); let mut buf = String::new(); buf.push_str("\n\nimpl "); @@ -70,8 +69,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { buf.push_str(" {\n"); let cursor_delta = if has_more_derives { + let delta = input.syntax().text_range().len() - TextSize::of(&new_attr_input); edit.replace(input.syntax().text_range(), new_attr_input); - input.syntax().text_range().len() - TextSize::from_usize(new_attr_input_len) + delta } else { let attr_range = attr.syntax().text_range(); edit.delete(attr_range); diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index 7a8f5705f..6c7456579 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -129,7 +129,7 @@ impl FunctionBuilder { let fn_def = indent_once.increase_indent(fn_def); let fn_def = ast::make::add_trailing_newlines(1, fn_def); let fn_def = indent.increase_indent(fn_def); - (fn_def, it.syntax().text_range().start() + TextSize::from_usize(1)) + (fn_def, it.syntax().text_range().start() + TextSize::of('{')) } }; diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 0698cce88..0f9174a29 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -77,13 +77,13 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option { .text_range() .end(); - Some((start, TextSize::from_usize(1))) + Some((start, TextSize::of("\n"))) }) .unwrap_or_else(|| { buf = generate_impl_text(&strukt, &buf); let start = strukt.syntax().text_range().end(); - (start, TextSize::from_usize(3)) + (start, TextSize::of("\n}\n")) }); edit.set_cursor(start_offset + TextSize::of(&buf) - end_offset); diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index cd0416f01..5a77d3dbc 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs @@ -89,7 +89,7 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { edit.target(current_text_range); edit.set_cursor(match cursor_pos { - CursorPos::InExpr(back_offset) => start + TextSize::from_usize(arm.len()) - back_offset, + CursorPos::InExpr(back_offset) => start + TextSize::of(&arm) - back_offset, CursorPos::InPat(offset) => offset, }); edit.replace(TextRange::new(start, end), arm); -- cgit v1.2.3