aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs8
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs10
-rw-r--r--crates/ra_assists/src/handlers/add_derive.rs8
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_from_impl_for_enum.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_function.rs8
-rw-r--r--crates/ra_assists/src/handlers/add_impl.rs4
-rw-r--r--crates/ra_assists/src/handlers/add_new.rs8
-rw-r--r--crates/ra_assists/src/handlers/apply_demorgan.rs2
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs4
-rw-r--r--crates/ra_assists/src/handlers/flip_binexpr.rs2
-rw-r--r--crates/ra_assists/src/handlers/inline_local_variable.rs2
-rw-r--r--crates/ra_assists/src/handlers/introduce_variable.rs6
-rw-r--r--crates/ra_assists/src/handlers/invert_if.rs2
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs10
-rw-r--r--crates/ra_assists/src/handlers/move_guard.rs10
-rw-r--r--crates/ra_assists/src/handlers/raw_string.rs4
-rw-r--r--crates/ra_assists/src/handlers/remove_dbg.rs8
-rw-r--r--crates/ra_assists/src/handlers/remove_mut.rs2
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs2
-rw-r--r--crates/ra_assists/src/lib.rs9
21 files changed, 58 insertions, 59 deletions
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};
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_syntax::{ 6use ra_syntax::{
7 algo::{self, find_covering_element, find_node_at_offset}, 7 algo::{self, find_covering_element, find_node_at_offset},
8 AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit, 8 AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
9 TokenAtOffset, 9 TokenAtOffset,
10}; 10};
11use ra_text_edit::TextEditBuilder; 11use ra_text_edit::TextEditBuilder;
@@ -178,7 +178,7 @@ impl<'a> AssistGroup<'a> {
178#[derive(Default)] 178#[derive(Default)]
179pub(crate) struct ActionBuilder { 179pub(crate) struct ActionBuilder {
180 edit: TextEditBuilder, 180 edit: TextEditBuilder,
181 cursor_position: Option<TextUnit>, 181 cursor_position: Option<TextSize>,
182 target: Option<TextRange>, 182 target: Option<TextRange>,
183 file: AssistFile, 183 file: AssistFile,
184} 184}
@@ -211,12 +211,12 @@ impl ActionBuilder {
211 } 211 }
212 212
213 /// Append specified `text` at the given `offset` 213 /// Append specified `text` at the given `offset`
214 pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into<String>) { 214 pub(crate) fn insert(&mut self, offset: TextSize, text: impl Into<String>) {
215 self.edit.insert(offset, text.into()) 215 self.edit.insert(offset, text.into())
216 } 216 }
217 217
218 /// Specify desired position of the cursor after the assist is applied. 218 /// Specify desired position of the cursor after the assist is applied.
219 pub(crate) fn set_cursor(&mut self, offset: TextUnit) { 219 pub(crate) fn set_cursor(&mut self, offset: TextSize) {
220 self.cursor_position = Some(offset) 220 self.cursor_position = Some(offset)
221 } 221 }
222 222
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index 15f9b216b..4ea26a550 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::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 Direction, SmolStr, 3 Direction, SmolStr,
4 SyntaxKind::{IDENT, WHITESPACE}, 4 SyntaxKind::{IDENT, WHITESPACE},
5 TextRange, TextUnit, 5 TextRange, TextSize,
6}; 6};
7use stdx::SepBy; 7use stdx::SepBy;
8 8
@@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
60 .collect::<Vec<SmolStr>>(); 60 .collect::<Vec<SmolStr>>();
61 let has_more_derives = !new_attr_input.is_empty(); 61 let has_more_derives = !new_attr_input.is_empty();
62 let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); 62 let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string();
63 let new_attr_input_len = new_attr_input.len();
64 63
65 let mut buf = String::new(); 64 let mut buf = String::new();
66 buf.push_str("\n\nimpl "); 65 buf.push_str("\n\nimpl ");
@@ -70,8 +69,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
70 buf.push_str(" {\n"); 69 buf.push_str(" {\n");
71 70
72 let cursor_delta = if has_more_derives { 71 let cursor_delta = if has_more_derives {
72 let delta = input.syntax().text_range().len() - TextSize::of(&new_attr_input);
73 edit.replace(input.syntax().text_range(), new_attr_input); 73 edit.replace(input.syntax().text_range(), new_attr_input);
74 input.syntax().text_range().len() - TextUnit::from_usize(new_attr_input_len) 74 delta
75 } else { 75 } else {
76 let attr_range = attr.syntax().text_range(); 76 let attr_range = attr.syntax().text_range();
77 edit.delete(attr_range); 77 edit.delete(attr_range);
@@ -81,13 +81,13 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
81 .next_sibling_or_token() 81 .next_sibling_or_token()
82 .filter(|t| t.kind() == WHITESPACE) 82 .filter(|t| t.kind() == WHITESPACE)
83 .map(|t| t.text_range()) 83 .map(|t| t.text_range())
84 .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); 84 .unwrap_or_else(|| TextRange::new(TextSize::from(0), TextSize::from(0)));
85 edit.delete(line_break_range); 85 edit.delete(line_break_range);
86 86
87 attr_range.len() + line_break_range.len() 87 attr_range.len() + line_break_range.len()
88 }; 88 };
89 89
90 edit.set_cursor(start_offset + TextUnit::of_str(&buf) - cursor_delta); 90 edit.set_cursor(start_offset + TextSize::of(&buf) - cursor_delta);
91 buf.push_str("\n}"); 91 buf.push_str("\n}");
92 edit.insert(start_offset, buf); 92 edit.insert(start_offset, buf);
93 }) 93 })
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 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode, AttrsOwner}, 2 ast::{self, AstNode, AttrsOwner},
3 SyntaxKind::{COMMENT, WHITESPACE}, 3 SyntaxKind::{COMMENT, WHITESPACE},
4 TextUnit, 4 TextSize,
5}; 5};
6 6
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{Assist, AssistCtx, AssistId};
@@ -37,9 +37,9 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
37 let offset = match derive_attr { 37 let offset = match derive_attr {
38 None => { 38 None => {
39 edit.insert(node_start, "#[derive()]\n"); 39 edit.insert(node_start, "#[derive()]\n");
40 node_start + TextUnit::of_str("#[derive(") 40 node_start + TextSize::of("#[derive(")
41 } 41 }
42 Some(tt) => tt.syntax().text_range().end() - TextUnit::of_char(')'), 42 Some(tt) => tt.syntax().text_range().end() - TextSize::of(')'),
43 }; 43 };
44 edit.target(nominal.syntax().text_range()); 44 edit.target(nominal.syntax().text_range());
45 edit.set_cursor(offset) 45 edit.set_cursor(offset)
@@ -47,7 +47,7 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
47} 47}
48 48
49// Insert `derive` after doc comments. 49// Insert `derive` after doc comments.
50fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> { 50fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> {
51 let non_ws_child = nominal 51 let non_ws_child = nominal
52 .syntax() 52 .syntax()
53 .children_with_tokens() 53 .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<Assist> {
37 let stmt_range = stmt.syntax().text_range(); 37 let stmt_range = stmt.syntax().text_range();
38 let eq_range = stmt.eq_token()?.text_range(); 38 let eq_range = stmt.eq_token()?.text_range();
39 // Assist should only be applicable if cursor is between 'let' and '=' 39 // Assist should only be applicable if cursor is between 'let' and '='
40 let let_range = TextRange::from_to(stmt_range.start(), eq_range.start()); 40 let let_range = TextRange::new(stmt_range.start(), eq_range.start());
41 let cursor_in_range = ctx.frange.range.is_subrange(&let_range); 41 let cursor_in_range = let_range.contains_range(ctx.frange.range);
42 if !cursor_in_range { 42 if !cursor_in_range {
43 return None; 43 return None;
44 } 44 }
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 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode, NameOwner}, 2 ast::{self, AstNode, NameOwner},
3 TextUnit, 3 TextSize,
4}; 4};
5use stdx::format_to; 5use stdx::format_to;
6 6
@@ -65,7 +65,7 @@ impl From<{0}> for {1} {{
65 variant_name 65 variant_name
66 ); 66 );
67 edit.insert(start_offset, buf); 67 edit.insert(start_offset, buf);
68 edit.set_cursor(start_offset + TextUnit::of_str("\n\n")); 68 edit.set_cursor(start_offset + TextSize::of("\n\n"));
69 }, 69 },
70 ) 70 )
71} 71}
diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs
index f185cffdb..6c7456579 100644
--- a/crates/ra_assists/src/handlers/add_function.rs
+++ b/crates/ra_assists/src/handlers/add_function.rs
@@ -1,6 +1,6 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 SyntaxKind, SyntaxNode, TextUnit, 3 SyntaxKind, SyntaxNode, TextSize,
4}; 4};
5 5
6use crate::{Assist, AssistCtx, AssistFile, AssistId}; 6use crate::{Assist, AssistCtx, AssistFile, AssistId};
@@ -69,8 +69,8 @@ pub(crate) fn add_function(ctx: AssistCtx) -> Option<Assist> {
69} 69}
70 70
71struct FunctionTemplate { 71struct FunctionTemplate {
72 insert_offset: TextUnit, 72 insert_offset: TextSize,
73 cursor_offset: TextUnit, 73 cursor_offset: TextSize,
74 fn_def: ast::SourceFile, 74 fn_def: ast::SourceFile,
75 file: AssistFile, 75 file: AssistFile,
76} 76}
@@ -129,7 +129,7 @@ impl FunctionBuilder {
129 let fn_def = indent_once.increase_indent(fn_def); 129 let fn_def = indent_once.increase_indent(fn_def);
130 let fn_def = ast::make::add_trailing_newlines(1, fn_def); 130 let fn_def = ast::make::add_trailing_newlines(1, fn_def);
131 let fn_def = indent.increase_indent(fn_def); 131 let fn_def = indent.increase_indent(fn_def);
132 (fn_def, it.syntax().text_range().start() + TextUnit::from_usize(1)) 132 (fn_def, it.syntax().text_range().start() + TextSize::of('{'))
133 } 133 }
134 }; 134 };
135 135
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 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode, NameOwner, TypeParamsOwner}, 2 ast::{self, AstNode, NameOwner, TypeParamsOwner},
3 TextUnit, 3 TextSize,
4}; 4};
5use stdx::{format_to, SepBy}; 5use stdx::{format_to, SepBy};
6 6
@@ -51,7 +51,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
51 format_to!(buf, "<{}>", generic_params) 51 format_to!(buf, "<{}>", generic_params)
52 } 52 }
53 buf.push_str(" {\n"); 53 buf.push_str(" {\n");
54 edit.set_cursor(start_offset + TextUnit::of_str(&buf)); 54 edit.set_cursor(start_offset + TextSize::of(&buf));
55 buf.push_str("\n}"); 55 buf.push_str("\n}");
56 edit.insert(start_offset, buf); 56 edit.insert(start_offset, buf);
57 }) 57 })
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs
index 240b19fa3..0f9174a29 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::{
3 ast::{ 3 ast::{
4 self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner, 4 self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner,
5 }, 5 },
6 TextUnit, T, 6 TextSize, T,
7}; 7};
8use stdx::{format_to, SepBy}; 8use stdx::{format_to, SepBy};
9 9
@@ -77,16 +77,16 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
77 .text_range() 77 .text_range()
78 .end(); 78 .end();
79 79
80 Some((start, TextUnit::from_usize(1))) 80 Some((start, TextSize::of("\n")))
81 }) 81 })
82 .unwrap_or_else(|| { 82 .unwrap_or_else(|| {
83 buf = generate_impl_text(&strukt, &buf); 83 buf = generate_impl_text(&strukt, &buf);
84 let start = strukt.syntax().text_range().end(); 84 let start = strukt.syntax().text_range().end();
85 85
86 (start, TextUnit::from_usize(3)) 86 (start, TextSize::of("\n}\n"))
87 }); 87 });
88 88
89 edit.set_cursor(start_offset + TextUnit::of_str(&buf) - end_offset); 89 edit.set_cursor(start_offset + TextSize::of(&buf) - end_offset);
90 edit.insert(start_offset, buf); 90 edit.insert(start_offset, buf);
91 }) 91 })
92} 92}
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<Assist> {
26 let op = expr.op_kind()?; 26 let op = expr.op_kind()?;
27 let op_range = expr.op_token()?.text_range(); 27 let op_range = expr.op_token()?.text_range();
28 let opposite_op = opposite_logic_op(op)?; 28 let opposite_op = opposite_logic_op(op)?;
29 let cursor_in_range = ctx.frange.range.is_subrange(&op_range); 29 let cursor_in_range = op_range.contains_range(ctx.frange.range);
30 if !cursor_in_range { 30 if !cursor_in_range {
31 return None; 31 return None;
32 } 32 }
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::{
5 ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY, 5 ATTR, COMMENT, CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY,
6 WHITESPACE, 6 WHITESPACE,
7 }, 7 },
8 SyntaxNode, TextUnit, T, 8 SyntaxNode, TextSize, T,
9}; 9};
10 10
11use crate::{Assist, AssistCtx, AssistId}; 11use crate::{Assist, AssistCtx, AssistId};
@@ -67,7 +67,7 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
67 }) 67 })
68} 68}
69 69
70fn vis_offset(node: &SyntaxNode) -> TextUnit { 70fn vis_offset(node: &SyntaxNode) -> TextSize {
71 node.children_with_tokens() 71 node.children_with_tokens()
72 .skip_while(|it| match it.kind() { 72 .skip_while(|it| match it.kind() {
73 WHITESPACE | COMMENT | ATTR => true, 73 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<Assist> {
23 let rhs = expr.rhs()?.syntax().clone(); 23 let rhs = expr.rhs()?.syntax().clone();
24 let op_range = expr.op_token()?.text_range(); 24 let op_range = expr.op_token()?.text_range();
25 // The assist should be applied only if the cursor is on the operator 25 // The assist should be applied only if the cursor is on the operator
26 let cursor_in_range = ctx.frange.range.is_subrange(&op_range); 26 let cursor_in_range = op_range.contains_range(ctx.frange.range);
27 if !cursor_in_range { 27 if !cursor_in_range {
28 return None; 28 return None;
29 } 29 }
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<Assist> {
52 .next_sibling_or_token() 52 .next_sibling_or_token()
53 .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone())) 53 .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone()))
54 { 54 {
55 TextRange::from_to( 55 TextRange::new(
56 let_stmt.syntax().text_range().start(), 56 let_stmt.syntax().text_range().start(),
57 whitespace.syntax().text_range().end(), 57 whitespace.syntax().text_range().end(),
58 ) 58 )
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::{
4 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, 4 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
5 WHITESPACE, 5 WHITESPACE,
6 }, 6 },
7 SyntaxNode, TextUnit, 7 SyntaxNode, TextSize,
8}; 8};
9use stdx::format_to; 9use stdx::format_to;
10use test_utils::tested_by; 10use test_utils::tested_by;
@@ -47,10 +47,10 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option<Assist> {
47 47
48 let cursor_offset = if wrap_in_block { 48 let cursor_offset = if wrap_in_block {
49 buf.push_str("{ let var_name = "); 49 buf.push_str("{ let var_name = ");
50 TextUnit::of_str("{ let ") 50 TextSize::of("{ let ")
51 } else { 51 } else {
52 buf.push_str("let var_name = "); 52 buf.push_str("let var_name = ");
53 TextUnit::of_str("let ") 53 TextSize::of("let ")
54 }; 54 };
55 format_to!(buf, "{}", expr.syntax()); 55 format_to!(buf, "{}", expr.syntax());
56 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); 56 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<Assist> {
28 let if_keyword = ctx.find_token_at_offset(T![if])?; 28 let if_keyword = ctx.find_token_at_offset(T![if])?;
29 let expr = ast::IfExpr::cast(if_keyword.parent())?; 29 let expr = ast::IfExpr::cast(if_keyword.parent())?;
30 let if_range = if_keyword.text_range(); 30 let if_range = if_keyword.text_range();
31 let cursor_in_range = ctx.frange.range.is_subrange(&if_range); 31 let cursor_in_range = if_range.contains_range(ctx.frange.range);
32 if !cursor_in_range { 32 if !cursor_in_range {
33 return None; 33 return None;
34 } 34 }
diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs
index eb967ab92..5a77d3dbc 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;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::neighbor, 4 algo::neighbor,
5 ast::{self, AstNode}, 5 ast::{self, AstNode},
6 Direction, TextUnit, 6 Direction, TextSize,
7}; 7};
8 8
9use crate::{Assist, AssistCtx, AssistId, TextRange}; 9use crate::{Assist, AssistCtx, AssistId, TextRange};
@@ -42,8 +42,8 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option<Assist> {
42 let current_text_range = current_arm.syntax().text_range(); 42 let current_text_range = current_arm.syntax().text_range();
43 43
44 enum CursorPos { 44 enum CursorPos {
45 InExpr(TextUnit), 45 InExpr(TextSize),
46 InPat(TextUnit), 46 InPat(TextSize),
47 } 47 }
48 let cursor_pos = ctx.frange.range.start(); 48 let cursor_pos = ctx.frange.range.start();
49 let cursor_pos = if current_expr.syntax().text_range().contains(cursor_pos) { 49 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<Assist> {
89 89
90 edit.target(current_text_range); 90 edit.target(current_text_range);
91 edit.set_cursor(match cursor_pos { 91 edit.set_cursor(match cursor_pos {
92 CursorPos::InExpr(back_offset) => start + TextUnit::from_usize(arm.len()) - back_offset, 92 CursorPos::InExpr(back_offset) => start + TextSize::of(&arm) - back_offset,
93 CursorPos::InPat(offset) => offset, 93 CursorPos::InPat(offset) => offset,
94 }); 94 });
95 edit.replace(TextRange::from_to(start, end), arm); 95 edit.replace(TextRange::new(start, end), arm);
96 }) 96 })
97} 97}
98 98
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 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast, 2 ast,
3 ast::{AstNode, AstToken, IfExpr, MatchArm}, 3 ast::{AstNode, AstToken, IfExpr, MatchArm},
4 TextUnit, 4 TextSize,
5}; 5};
6 6
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{Assist, AssistCtx, AssistId};
@@ -49,16 +49,16 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> {
49 edit.delete(ele); 49 edit.delete(ele);
50 ele.len() 50 ele.len()
51 } else { 51 } else {
52 TextUnit::from(0) 52 TextSize::from(0)
53 } 53 }
54 } 54 }
55 _ => TextUnit::from(0), 55 _ => TextSize::from(0),
56 }; 56 };
57 57
58 edit.delete(guard.syntax().text_range()); 58 edit.delete(guard.syntax().text_range());
59 edit.replace_node_and_indent(arm_expr.syntax(), buf); 59 edit.replace_node_and_indent(arm_expr.syntax(), buf);
60 edit.set_cursor( 60 edit.set_cursor(
61 arm_expr.syntax().text_range().start() + TextUnit::from(3) - offseting_amount, 61 arm_expr.syntax().text_range().start() + TextSize::from(3) - offseting_amount,
62 ); 62 );
63 }) 63 })
64} 64}
@@ -123,7 +123,7 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
123 } 123 }
124 124
125 edit.insert(match_pat.syntax().text_range().end(), buf); 125 edit.insert(match_pat.syntax().text_range().end(), buf);
126 edit.set_cursor(match_pat.syntax().text_range().end() + TextUnit::from(1)); 126 edit.set_cursor(match_pat.syntax().text_range().end() + TextSize::from(1));
127 }, 127 },
128 ) 128 )
129} 129}
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::{
2 ast::{self, HasStringValue}, 2 ast::{self, HasStringValue},
3 AstToken, 3 AstToken,
4 SyntaxKind::{RAW_STRING, STRING}, 4 SyntaxKind::{RAW_STRING, STRING},
5 TextUnit, 5 TextSize,
6}; 6};
7 7
8use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
@@ -81,7 +81,7 @@ pub(crate) fn add_hash(ctx: AssistCtx) -> Option<Assist> {
81 let token = ctx.find_token_at_offset(RAW_STRING)?; 81 let token = ctx.find_token_at_offset(RAW_STRING)?;
82 ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| { 82 ctx.add_assist(AssistId("add_hash"), "Add # to raw string", |edit| {
83 edit.target(token.text_range()); 83 edit.target(token.text_range());
84 edit.insert(token.text_range().start() + TextUnit::of_char('r'), "#"); 84 edit.insert(token.text_range().start() + TextSize::of('r'), "#");
85 edit.insert(token.text_range().end(), "#"); 85 edit.insert(token.text_range().end(), "#");
86 }) 86 })
87} 87}
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 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 TextUnit, T, 3 TextSize, T,
4}; 4};
5 5
6use crate::{Assist, AssistCtx, AssistId}; 6use crate::{Assist, AssistCtx, AssistId};
@@ -38,9 +38,9 @@ pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option<Assist> {
38 let offset_start = file_range 38 let offset_start = file_range
39 .start() 39 .start()
40 .checked_sub(macro_range.start()) 40 .checked_sub(macro_range.start())
41 .unwrap_or_else(|| TextUnit::from(0)); 41 .unwrap_or_else(|| TextSize::from(0));
42 42
43 let dbg_size = TextUnit::of_str("dbg!("); 43 let dbg_size = TextSize::of("dbg!(");
44 44
45 if offset_start > dbg_size { 45 if offset_start > dbg_size {
46 file_range.start() - dbg_size 46 file_range.start() - dbg_size
@@ -53,7 +53,7 @@ pub(crate) fn remove_dbg(ctx: AssistCtx) -> Option<Assist> {
53 let macro_args = macro_call.token_tree()?.syntax().clone(); 53 let macro_args = macro_call.token_tree()?.syntax().clone();
54 54
55 let text = macro_args.text(); 55 let text = macro_args.text();
56 let without_parens = TextUnit::of_char('(')..text.len() - TextUnit::of_char(')'); 56 let without_parens = TextSize::of('(')..text.len() - TextSize::of(')');
57 text.slice(without_parens).to_string() 57 text.slice(without_parens).to_string()
58 }; 58 };
59 59
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<Assist> {
27 27
28 ctx.add_assist(AssistId("remove_mut"), "Remove `mut` keyword", |edit| { 28 ctx.add_assist(AssistId("remove_mut"), "Remove `mut` keyword", |edit| {
29 edit.set_cursor(delete_from); 29 edit.set_cursor(delete_from);
30 edit.delete(TextRange::from_to(delete_from, delete_to)); 30 edit.delete(TextRange::new(delete_from, delete_to));
31 }) 31 })
32} 32}
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<Assist>
43 if let Some(last) = path.segment() { 43 if let Some(last) = path.segment() {
44 // Here we are assuming the assist will provide a correct use statement 44 // Here we are assuming the assist will provide a correct use statement
45 // so we can delete the path qualifier 45 // so we can delete the path qualifier
46 edit.delete(TextRange::from_to( 46 edit.delete(TextRange::new(
47 path.syntax().text_range().start(), 47 path.syntax().text_range().start(),
48 last.syntax().text_range().start(), 48 last.syntax().text_range().start(),
49 )); 49 ));
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index ccc95735f..64bd87afb 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -19,7 +19,7 @@ pub mod ast_transform;
19 19
20use ra_db::{FileId, FileRange}; 20use ra_db::{FileId, FileRange};
21use ra_ide_db::RootDatabase; 21use ra_ide_db::RootDatabase;
22use ra_syntax::{TextRange, TextUnit}; 22use ra_syntax::{TextRange, TextSize};
23use ra_text_edit::TextEdit; 23use ra_text_edit::TextEdit;
24 24
25pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; 25pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler};
@@ -51,7 +51,7 @@ impl AssistLabel {
51#[derive(Debug, Clone)] 51#[derive(Debug, Clone)]
52pub struct AssistAction { 52pub struct AssistAction {
53 pub edit: TextEdit, 53 pub edit: TextEdit,
54 pub cursor_position: Option<TextUnit>, 54 pub cursor_position: Option<TextSize>,
55 // FIXME: This belongs to `AssistLabel` 55 // FIXME: This belongs to `AssistLabel`
56 pub target: Option<TextRange>, 56 pub target: Option<TextRange>,
57 pub file: AssistFile, 57 pub file: AssistFile,
@@ -104,7 +104,7 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssi
104 .flat_map(|it| it.0) 104 .flat_map(|it| it.0)
105 .map(|it| it.into_resolved().unwrap()) 105 .map(|it| it.into_resolved().unwrap())
106 .collect::<Vec<_>>(); 106 .collect::<Vec<_>>();
107 a.sort_by_key(|it| it.action.target.map_or(TextUnit::from(!0u32), |it| it.len())); 107 a.sort_by_key(|it| it.action.target.map_or(TextSize::from(!0u32), |it| it.len()));
108 a 108 a
109} 109}
110 110
@@ -308,8 +308,7 @@ mod tests {
308 let before = "struct Foo { <|>bar: u32 }"; 308 let before = "struct Foo { <|>bar: u32 }";
309 let (before_cursor_pos, before) = extract_offset(before); 309 let (before_cursor_pos, before) = extract_offset(before);
310 let (db, file_id) = helpers::with_single_file(&before); 310 let (db, file_id) = helpers::with_single_file(&before);
311 let frange = 311 let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
312 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
313 let assists = resolved_assists(&db, frange); 312 let assists = resolved_assists(&db, frange);
314 let mut assists = assists.iter(); 313 let mut assists = assists.iter();
315 314