aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/add_derive.rs6
-rw-r--r--crates/ra_assists/src/add_explicit_type.rs4
-rw-r--r--crates/ra_assists/src/add_impl.rs4
-rw-r--r--crates/ra_assists/src/add_missing_impl_members.rs4
-rw-r--r--crates/ra_assists/src/assist_ctx.rs2
-rw-r--r--crates/ra_assists/src/ast_editor.rs5
-rw-r--r--crates/ra_assists/src/auto_import.rs18
-rw-r--r--crates/ra_assists/src/change_visibility.rs23
-rw-r--r--crates/ra_assists/src/fill_match_arms.rs4
-rw-r--r--crates/ra_assists/src/flip_binexpr.rs6
-rw-r--r--crates/ra_assists/src/flip_comma.rs6
-rw-r--r--crates/ra_assists/src/inline_local_variable.rs7
-rw-r--r--crates/ra_assists/src/introduce_variable.rs12
-rw-r--r--crates/ra_assists/src/move_guard.rs20
-rw-r--r--crates/ra_assists/src/remove_dbg.rs4
-rw-r--r--crates/ra_assists/src/replace_if_let_with_match.rs4
-rw-r--r--crates/ra_assists/src/split_import.rs8
17 files changed, 73 insertions, 64 deletions
diff --git a/crates/ra_assists/src/add_derive.rs b/crates/ra_assists/src/add_derive.rs
index f19196f53..9c88644df 100644
--- a/crates/ra_assists/src/add_derive.rs
+++ b/crates/ra_assists/src/add_derive.rs
@@ -22,9 +22,9 @@ pub(crate) fn add_derive(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist>
22 edit.insert(node_start, "#[derive()]\n"); 22 edit.insert(node_start, "#[derive()]\n");
23 node_start + TextUnit::of_str("#[derive(") 23 node_start + TextUnit::of_str("#[derive(")
24 } 24 }
25 Some(tt) => tt.syntax().range().end() - TextUnit::of_char(')'), 25 Some(tt) => tt.syntax().text_range().end() - TextUnit::of_char(')'),
26 }; 26 };
27 edit.target(nominal.syntax().range()); 27 edit.target(nominal.syntax().text_range());
28 edit.set_cursor(offset) 28 edit.set_cursor(offset)
29 }); 29 });
30 30
@@ -37,7 +37,7 @@ fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> {
37 .syntax() 37 .syntax()
38 .children_with_tokens() 38 .children_with_tokens()
39 .find(|it| it.kind() != COMMENT && it.kind() != WHITESPACE)?; 39 .find(|it| it.kind() != COMMENT && it.kind() != WHITESPACE)?;
40 Some(non_ws_child.range().start()) 40 Some(non_ws_child.text_range().start())
41} 41}
42 42
43#[cfg(test)] 43#[cfg(test)]
diff --git a/crates/ra_assists/src/add_explicit_type.rs b/crates/ra_assists/src/add_explicit_type.rs
index a69cfc8e3..88970929f 100644
--- a/crates/ra_assists/src/add_explicit_type.rs
+++ b/crates/ra_assists/src/add_explicit_type.rs
@@ -16,10 +16,10 @@ pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option<
16 PatKind::BindPat(bind_pat) => bind_pat, 16 PatKind::BindPat(bind_pat) => bind_pat,
17 _ => return None, 17 _ => return None,
18 }; 18 };
19 let pat_range = pat.syntax().range(); 19 let pat_range = pat.syntax().text_range();
20 // The binding must have a name 20 // The binding must have a name
21 let name = pat.name()?; 21 let name = pat.name()?;
22 let name_range = name.syntax().range(); 22 let name_range = name.syntax().text_range();
23 // Assist not applicable if the type has already been specified 23 // Assist not applicable if the type has already been specified
24 if stmt.syntax().children_with_tokens().any(|child| child.kind() == T![:]) { 24 if stmt.syntax().children_with_tokens().any(|child| child.kind() == T![:]) {
25 return None; 25 return None;
diff --git a/crates/ra_assists/src/add_impl.rs b/crates/ra_assists/src/add_impl.rs
index cebc19539..9a0cfb4e7 100644
--- a/crates/ra_assists/src/add_impl.rs
+++ b/crates/ra_assists/src/add_impl.rs
@@ -11,9 +11,9 @@ pub(crate) fn add_impl(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
11 let nominal = ctx.node_at_offset::<ast::NominalDef>()?; 11 let nominal = ctx.node_at_offset::<ast::NominalDef>()?;
12 let name = nominal.name()?; 12 let name = nominal.name()?;
13 ctx.add_action(AssistId("add_impl"), "add impl", |edit| { 13 ctx.add_action(AssistId("add_impl"), "add impl", |edit| {
14 edit.target(nominal.syntax().range()); 14 edit.target(nominal.syntax().text_range());
15 let type_params = nominal.type_param_list(); 15 let type_params = nominal.type_param_list();
16 let start_offset = nominal.syntax().range().end(); 16 let start_offset = nominal.syntax().text_range().end();
17 let mut buf = String::new(); 17 let mut buf = String::new();
18 buf.push_str("\n\nimpl"); 18 buf.push_str("\n\nimpl");
19 if let Some(type_params) = &type_params { 19 if let Some(type_params) = &type_params {
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs
index b992a4dc8..995e44d5e 100644
--- a/crates/ra_assists/src/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/add_missing_impl_members.rs
@@ -43,7 +43,7 @@ fn add_missing_impl_members_inner(
43 43
44 let trait_def = { 44 let trait_def = {
45 let file_id = ctx.frange.file_id; 45 let file_id = ctx.frange.file_id;
46 let position = FilePosition { file_id, offset: impl_node.syntax().range().start() }; 46 let position = FilePosition { file_id, offset: impl_node.syntax().text_range().start() };
47 let analyzer = hir::SourceAnalyzer::new(ctx.db, position.file_id, impl_node.syntax(), None); 47 let analyzer = hir::SourceAnalyzer::new(ctx.db, position.file_id, impl_node.syntax(), None);
48 48
49 resolve_target_trait_def(ctx.db, &analyzer, &impl_node)? 49 resolve_target_trait_def(ctx.db, &analyzer, &impl_node)?
@@ -87,7 +87,7 @@ fn add_missing_impl_members_inner(
87 ast_editor.append_items(items); 87 ast_editor.append_items(items);
88 88
89 let first_new_item = ast_editor.ast().impl_items().nth(n_existing_items).unwrap(); 89 let first_new_item = ast_editor.ast().impl_items().nth(n_existing_items).unwrap();
90 let cursor_position = first_new_item.syntax().range().start(); 90 let cursor_position = first_new_item.syntax().text_range().start();
91 ast_editor.into_text_edit(edit.text_edit_builder()); 91 ast_editor.into_text_edit(edit.text_edit_builder());
92 92
93 edit.set_cursor(cursor_position); 93 edit.set_cursor(cursor_position);
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index e52085f85..4d5a76de6 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -141,7 +141,7 @@ impl AssistBuilder {
141 if let Some(indent) = leading_indent(node) { 141 if let Some(indent) = leading_indent(node) {
142 replace_with = reindent(&replace_with, &indent) 142 replace_with = reindent(&replace_with, &indent)
143 } 143 }
144 self.replace(node.range(), replace_with) 144 self.replace(node.text_range(), replace_with)
145 } 145 }
146 146
147 pub(crate) fn set_edit_builder(&mut self, edit: TextEditBuilder) { 147 pub(crate) fn set_edit_builder(&mut self, edit: TextEditBuilder) {
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs
index a35334d7e..36235eb13 100644
--- a/crates/ra_assists/src/ast_editor.rs
+++ b/crates/ra_assists/src/ast_editor.rs
@@ -22,7 +22,10 @@ impl<N: AstNode> AstEditor<N> {
22 // FIXME: compute a more fine-grained diff here. 22 // FIXME: compute a more fine-grained diff here.
23 // If *you* know a nice algorithm to compute diff between two syntax 23 // If *you* know a nice algorithm to compute diff between two syntax
24 // tree, tell me about it! 24 // tree, tell me about it!
25 builder.replace(self.original_ast.syntax().range(), self.ast().syntax().text().to_string()); 25 builder.replace(
26 self.original_ast.syntax().text_range(),
27 self.ast().syntax().text().to_string(),
28 );
26 } 29 }
27 30
28 pub fn ast(&self) -> &N { 31 pub fn ast(&self) -> &N {
diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs
index 0eb4bdb62..43e75eee1 100644
--- a/crates/ra_assists/src/auto_import.rs
+++ b/crates/ra_assists/src/auto_import.rs
@@ -356,7 +356,7 @@ fn best_action_for_target(
356 // todo: we should include even whitespace blocks as anchor candidates 356 // todo: we should include even whitespace blocks as anchor candidates
357 let anchor = container 357 let anchor = container
358 .children() 358 .children()
359 .find(|n| n.range().start() < anchor.range().start()) 359 .find(|n| n.text_range().start() < anchor.text_range().start())
360 .or_else(|| Some(anchor)); 360 .or_else(|| Some(anchor));
361 361
362 ImportAction::add_new_use(anchor, false) 362 ImportAction::add_new_use(anchor, false)
@@ -418,7 +418,7 @@ fn make_assist_add_new_use(
418 buf.push_str(&spaces); 418 buf.push_str(&spaces);
419 } 419 }
420 } 420 }
421 let position = if after { anchor.range().end() } else { anchor.range().start() }; 421 let position = if after { anchor.text_range().end() } else { anchor.text_range().start() };
422 edit.insert(position, buf); 422 edit.insert(position, buf);
423 } 423 }
424} 424}
@@ -434,10 +434,10 @@ fn make_assist_add_in_tree_list(
434 let mut buf = String::new(); 434 let mut buf = String::new();
435 let comma = last.syntax().siblings(Direction::Next).find(|n| n.kind() == T![,]); 435 let comma = last.syntax().siblings(Direction::Next).find(|n| n.kind() == T![,]);
436 let offset = if let Some(comma) = comma { 436 let offset = if let Some(comma) = comma {
437 comma.range().end() 437 comma.text_range().end()
438 } else { 438 } else {
439 buf.push_str(","); 439 buf.push_str(",");
440 last.syntax().range().end() 440 last.syntax().text_range().end()
441 }; 441 };
442 if add_self { 442 if add_self {
443 buf.push_str(" self") 443 buf.push_str(" self")
@@ -462,11 +462,11 @@ fn make_assist_add_nested_import(
462 if let Some(use_tree) = use_tree { 462 if let Some(use_tree) = use_tree {
463 let (start, add_colon_colon) = if let Some(first_segment_to_split) = first_segment_to_split 463 let (start, add_colon_colon) = if let Some(first_segment_to_split) = first_segment_to_split
464 { 464 {
465 (first_segment_to_split.syntax().range().start(), false) 465 (first_segment_to_split.syntax().text_range().start(), false)
466 } else { 466 } else {
467 (use_tree.syntax().range().end(), true) 467 (use_tree.syntax().text_range().end(), true)
468 }; 468 };
469 let end = use_tree.syntax().range().end(); 469 let end = use_tree.syntax().text_range().end();
470 470
471 let mut buf = String::new(); 471 let mut buf = String::new();
472 if add_colon_colon { 472 if add_colon_colon {
@@ -497,8 +497,8 @@ fn apply_auto_import(
497 // Here we are assuming the assist will provide a correct use statement 497 // Here we are assuming the assist will provide a correct use statement
498 // so we can delete the path qualifier 498 // so we can delete the path qualifier
499 edit.delete(TextRange::from_to( 499 edit.delete(TextRange::from_to(
500 path.syntax().range().start(), 500 path.syntax().text_range().start(),
501 last.syntax().range().start(), 501 last.syntax().text_range().start(),
502 )); 502 ));
503 } 503 }
504} 504}
diff --git a/crates/ra_assists/src/change_visibility.rs b/crates/ra_assists/src/change_visibility.rs
index ab10d2aa4..d28cdd07b 100644
--- a/crates/ra_assists/src/change_visibility.rs
+++ b/crates/ra_assists/src/change_visibility.rs
@@ -35,14 +35,15 @@ fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
35 if parent.children().any(|child| child.kind() == VISIBILITY) { 35 if parent.children().any(|child| child.kind() == VISIBILITY) {
36 return None; 36 return None;
37 } 37 }
38 (vis_offset(&parent), keyword.range()) 38 (vis_offset(&parent), keyword.text_range())
39 } else { 39 } else {
40 let ident = ctx.token_at_offset().find(|leaf| leaf.kind() == IDENT)?; 40 let ident = ctx.token_at_offset().find(|leaf| leaf.kind() == IDENT)?;
41 let field = ident.parent().ancestors().find_map(ast::NamedFieldDef::cast)?; 41 let field = ident.parent().ancestors().find_map(ast::NamedFieldDef::cast)?;
42 if field.name()?.syntax().range() != ident.range() && field.visibility().is_some() { 42 if field.name()?.syntax().text_range() != ident.text_range() && field.visibility().is_some()
43 {
43 return None; 44 return None;
44 } 45 }
45 (vis_offset(field.syntax()), ident.range()) 46 (vis_offset(field.syntax()), ident.text_range())
46 }; 47 };
47 48
48 ctx.add_action(AssistId("change_visibility"), "make pub(crate)", |edit| { 49 ctx.add_action(AssistId("change_visibility"), "make pub(crate)", |edit| {
@@ -61,25 +62,25 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit {
61 _ => false, 62 _ => false,
62 }) 63 })
63 .next() 64 .next()
64 .map(|it| it.range().start()) 65 .map(|it| it.text_range().start())
65 .unwrap_or_else(|| node.range().start()) 66 .unwrap_or_else(|| node.text_range().start())
66} 67}
67 68
68fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: ast::Visibility) -> Option<Assist> { 69fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: ast::Visibility) -> Option<Assist> {
69 if vis.syntax().text() == "pub" { 70 if vis.syntax().text() == "pub" {
70 ctx.add_action(AssistId("change_visibility"), "change to pub(crate)", |edit| { 71 ctx.add_action(AssistId("change_visibility"), "change to pub(crate)", |edit| {
71 edit.target(vis.syntax().range()); 72 edit.target(vis.syntax().text_range());
72 edit.replace(vis.syntax().range(), "pub(crate)"); 73 edit.replace(vis.syntax().text_range(), "pub(crate)");
73 edit.set_cursor(vis.syntax().range().start()) 74 edit.set_cursor(vis.syntax().text_range().start())
74 }); 75 });
75 76
76 return ctx.build(); 77 return ctx.build();
77 } 78 }
78 if vis.syntax().text() == "pub(crate)" { 79 if vis.syntax().text() == "pub(crate)" {
79 ctx.add_action(AssistId("change_visibility"), "change to pub", |edit| { 80 ctx.add_action(AssistId("change_visibility"), "change to pub", |edit| {
80 edit.target(vis.syntax().range()); 81 edit.target(vis.syntax().text_range());
81 edit.replace(vis.syntax().range(), "pub"); 82 edit.replace(vis.syntax().text_range(), "pub");
82 edit.set_cursor(vis.syntax().range().start()); 83 edit.set_cursor(vis.syntax().text_range().start());
83 }); 84 });
84 85
85 return ctx.build(); 86 return ctx.build();
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs
index b96806ac6..939429892 100644
--- a/crates/ra_assists/src/fill_match_arms.rs
+++ b/crates/ra_assists/src/fill_match_arms.rs
@@ -84,8 +84,8 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As
84 buf.push_str(" => (),\n"); 84 buf.push_str(" => (),\n");
85 } 85 }
86 buf.push_str("}"); 86 buf.push_str("}");
87 edit.target(match_expr.syntax().range()); 87 edit.target(match_expr.syntax().text_range());
88 edit.set_cursor(expr.syntax().range().start()); 88 edit.set_cursor(expr.syntax().text_range().start());
89 edit.replace_node_and_indent(match_expr.syntax(), buf); 89 edit.replace_node_and_indent(match_expr.syntax(), buf);
90 }); 90 });
91 91
diff --git a/crates/ra_assists/src/flip_binexpr.rs b/crates/ra_assists/src/flip_binexpr.rs
index 2e591ad3b..b55b36a8e 100644
--- a/crates/ra_assists/src/flip_binexpr.rs
+++ b/crates/ra_assists/src/flip_binexpr.rs
@@ -8,7 +8,7 @@ pub(crate) fn flip_binexpr(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
8 let expr = ctx.node_at_offset::<BinExpr>()?; 8 let expr = ctx.node_at_offset::<BinExpr>()?;
9 let lhs = expr.lhs()?.syntax().clone(); 9 let lhs = expr.lhs()?.syntax().clone();
10 let rhs = expr.rhs()?.syntax().clone(); 10 let rhs = expr.rhs()?.syntax().clone();
11 let op_range = expr.op_token()?.range(); 11 let op_range = expr.op_token()?.text_range();
12 // The assist should be applied only if the cursor is on the operator 12 // The assist should be applied only if the cursor is on the operator
13 let cursor_in_range = ctx.frange.range.is_subrange(&op_range); 13 let cursor_in_range = ctx.frange.range.is_subrange(&op_range);
14 if !cursor_in_range { 14 if !cursor_in_range {
@@ -25,8 +25,8 @@ pub(crate) fn flip_binexpr(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
25 if let FlipAction::FlipAndReplaceOp(new_op) = action { 25 if let FlipAction::FlipAndReplaceOp(new_op) = action {
26 edit.replace(op_range, new_op); 26 edit.replace(op_range, new_op);
27 } 27 }
28 edit.replace(lhs.range(), rhs.text()); 28 edit.replace(lhs.text_range(), rhs.text());
29 edit.replace(rhs.range(), lhs.text()); 29 edit.replace(rhs.text_range(), lhs.text());
30 }); 30 });
31 31
32 ctx.build() 32 ctx.build()
diff --git a/crates/ra_assists/src/flip_comma.rs b/crates/ra_assists/src/flip_comma.rs
index 13016ae06..34489329c 100644
--- a/crates/ra_assists/src/flip_comma.rs
+++ b/crates/ra_assists/src/flip_comma.rs
@@ -8,9 +8,9 @@ pub(crate) fn flip_comma(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist>
8 let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; 8 let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?;
9 let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?; 9 let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?;
10 ctx.add_action(AssistId("flip_comma"), "flip comma", |edit| { 10 ctx.add_action(AssistId("flip_comma"), "flip comma", |edit| {
11 edit.target(comma.range()); 11 edit.target(comma.text_range());
12 edit.replace(prev.range(), next.to_string()); 12 edit.replace(prev.text_range(), next.to_string());
13 edit.replace(next.range(), prev.to_string()); 13 edit.replace(next.text_range(), prev.to_string());
14 }); 14 });
15 15
16 ctx.build() 16 ctx.build()
diff --git a/crates/ra_assists/src/inline_local_variable.rs b/crates/ra_assists/src/inline_local_variable.rs
index 3c17089de..82c4d54b0 100644
--- a/crates/ra_assists/src/inline_local_variable.rs
+++ b/crates/ra_assists/src/inline_local_variable.rs
@@ -22,9 +22,12 @@ pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Opt
22 .next_sibling_or_token() 22 .next_sibling_or_token()
23 .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone())) 23 .and_then(|it| ast::Whitespace::cast(it.as_token()?.clone()))
24 { 24 {
25 TextRange::from_to(let_stmt.syntax().range().start(), whitespace.syntax().range().end()) 25 TextRange::from_to(
26 let_stmt.syntax().text_range().start(),
27 whitespace.syntax().text_range().end(),
28 )
26 } else { 29 } else {
27 let_stmt.syntax().range() 30 let_stmt.syntax().text_range()
28 }; 31 };
29 let analyzer = hir::SourceAnalyzer::new(ctx.db, ctx.frange.file_id, bind_pat.syntax(), None); 32 let analyzer = hir::SourceAnalyzer::new(ctx.db, ctx.frange.file_id, bind_pat.syntax(), None);
30 let refs = analyzer.find_all_refs(&bind_pat); 33 let refs = analyzer.find_all_refs(&bind_pat);
diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs
index ce28132c9..df6c58989 100644
--- a/crates/ra_assists/src/introduce_variable.rs
+++ b/crates/ra_assists/src/introduce_variable.rs
@@ -48,7 +48,7 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option
48 if !full_stmt.unwrap().has_semi() { 48 if !full_stmt.unwrap().has_semi() {
49 buf.push_str(";"); 49 buf.push_str(";");
50 } 50 }
51 edit.replace(expr.syntax().range(), buf); 51 edit.replace(expr.syntax().text_range(), buf);
52 } else { 52 } else {
53 buf.push_str(";"); 53 buf.push_str(";");
54 54
@@ -66,14 +66,14 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option
66 buf.push_str(text); 66 buf.push_str(text);
67 } 67 }
68 68
69 edit.target(expr.syntax().range()); 69 edit.target(expr.syntax().text_range());
70 edit.replace(expr.syntax().range(), "var_name".to_string()); 70 edit.replace(expr.syntax().text_range(), "var_name".to_string());
71 edit.insert(anchor_stmt.range().start(), buf); 71 edit.insert(anchor_stmt.text_range().start(), buf);
72 if wrap_in_block { 72 if wrap_in_block {
73 edit.insert(anchor_stmt.range().end(), " }"); 73 edit.insert(anchor_stmt.text_range().end(), " }");
74 } 74 }
75 } 75 }
76 edit.set_cursor(anchor_stmt.range().start() + cursor_offset); 76 edit.set_cursor(anchor_stmt.text_range().start() + cursor_offset);
77 }); 77 });
78 78
79 ctx.build() 79 ctx.build()
diff --git a/crates/ra_assists/src/move_guard.rs b/crates/ra_assists/src/move_guard.rs
index 313c9ad18..0f3cdbe53 100644
--- a/crates/ra_assists/src/move_guard.rs
+++ b/crates/ra_assists/src/move_guard.rs
@@ -17,11 +17,11 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Op
17 let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text()); 17 let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text());
18 18
19 ctx.add_action(AssistId("move_guard_to_arm_body"), "move guard to arm body", |edit| { 19 ctx.add_action(AssistId("move_guard_to_arm_body"), "move guard to arm body", |edit| {
20 edit.target(guard.syntax().range()); 20 edit.target(guard.syntax().text_range());
21 let offseting_amount = match &space_before_guard { 21 let offseting_amount = match &space_before_guard {
22 Some(SyntaxElement::Token(tok)) => { 22 Some(SyntaxElement::Token(tok)) => {
23 if let Some(_) = ast::Whitespace::cast(tok.clone()) { 23 if let Some(_) = ast::Whitespace::cast(tok.clone()) {
24 let ele = space_before_guard.unwrap().range(); 24 let ele = space_before_guard.unwrap().text_range();
25 edit.delete(ele); 25 edit.delete(ele);
26 ele.len() 26 ele.len()
27 } else { 27 } else {
@@ -31,9 +31,11 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Op
31 _ => TextUnit::from(0), 31 _ => TextUnit::from(0),
32 }; 32 };
33 33
34 edit.delete(guard.syntax().range()); 34 edit.delete(guard.syntax().text_range());
35 edit.replace_node_and_indent(arm_expr.syntax(), buf); 35 edit.replace_node_and_indent(arm_expr.syntax(), buf);
36 edit.set_cursor(arm_expr.syntax().range().start() + TextUnit::from(3) - offseting_amount); 36 edit.set_cursor(
37 arm_expr.syntax().text_range().start() + TextUnit::from(3) - offseting_amount,
38 );
37 }); 39 });
38 ctx.build() 40 ctx.build()
39} 41}
@@ -62,18 +64,18 @@ pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx<impl HirDatabase>)
62 AssistId("move_arm_cond_to_match_guard"), 64 AssistId("move_arm_cond_to_match_guard"),
63 "move condition to match guard", 65 "move condition to match guard",
64 |edit| { 66 |edit| {
65 edit.target(if_expr.syntax().range()); 67 edit.target(if_expr.syntax().text_range());
66 let then_only_expr = then_block.statements().next().is_none(); 68 let then_only_expr = then_block.statements().next().is_none();
67 69
68 match &then_block.expr() { 70 match &then_block.expr() {
69 Some(then_expr) if then_only_expr => { 71 Some(then_expr) if then_only_expr => {
70 edit.replace(if_expr.syntax().range(), then_expr.syntax().text()) 72 edit.replace(if_expr.syntax().text_range(), then_expr.syntax().text())
71 } 73 }
72 _ => edit.replace(if_expr.syntax().range(), then_block.syntax().text()), 74 _ => edit.replace(if_expr.syntax().text_range(), then_block.syntax().text()),
73 } 75 }
74 76
75 edit.insert(last_match_pat.syntax().range().end(), buf); 77 edit.insert(last_match_pat.syntax().text_range().end(), buf);
76 edit.set_cursor(last_match_pat.syntax().range().end() + TextUnit::from(1)); 78 edit.set_cursor(last_match_pat.syntax().text_range().end() + TextUnit::from(1));
77 }, 79 },
78 ); 80 );
79 ctx.build() 81 ctx.build()
diff --git a/crates/ra_assists/src/remove_dbg.rs b/crates/ra_assists/src/remove_dbg.rs
index 5657ee4b8..870133fda 100644
--- a/crates/ra_assists/src/remove_dbg.rs
+++ b/crates/ra_assists/src/remove_dbg.rs
@@ -12,7 +12,7 @@ pub(crate) fn remove_dbg(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist>
12 return None; 12 return None;
13 } 13 }
14 14
15 let macro_range = macro_call.syntax().range(); 15 let macro_range = macro_call.syntax().text_range();
16 16
17 // If the cursor is inside the macro call, we'll try to maintain the cursor 17 // If the cursor is inside the macro call, we'll try to maintain the cursor
18 // position by subtracting the length of dbg!( from the start of the file 18 // position by subtracting the length of dbg!( from the start of the file
@@ -43,7 +43,7 @@ pub(crate) fn remove_dbg(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist>
43 }; 43 };
44 44
45 ctx.add_action(AssistId("remove_dbg"), "remove dbg!()", |edit| { 45 ctx.add_action(AssistId("remove_dbg"), "remove dbg!()", |edit| {
46 edit.target(macro_call.syntax().range()); 46 edit.target(macro_call.syntax().text_range());
47 edit.replace(macro_range, macro_content); 47 edit.replace(macro_range, macro_content);
48 edit.set_cursor(cursor_pos); 48 edit.set_cursor(cursor_pos);
49 }); 49 });
diff --git a/crates/ra_assists/src/replace_if_let_with_match.rs b/crates/ra_assists/src/replace_if_let_with_match.rs
index 5de6aa266..c0bf6d235 100644
--- a/crates/ra_assists/src/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/replace_if_let_with_match.rs
@@ -17,9 +17,9 @@ pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) ->
17 17
18 ctx.add_action(AssistId("replace_if_let_with_match"), "replace with match", |edit| { 18 ctx.add_action(AssistId("replace_if_let_with_match"), "replace with match", |edit| {
19 let match_expr = build_match_expr(expr, pat, then_block, else_block); 19 let match_expr = build_match_expr(expr, pat, then_block, else_block);
20 edit.target(if_expr.syntax().range()); 20 edit.target(if_expr.syntax().text_range());
21 edit.replace_node_and_indent(if_expr.syntax(), match_expr); 21 edit.replace_node_and_indent(if_expr.syntax(), match_expr);
22 edit.set_cursor(if_expr.syntax().range().start()) 22 edit.set_cursor(if_expr.syntax().text_range().start())
23 }); 23 });
24 24
25 ctx.build() 25 ctx.build()
diff --git a/crates/ra_assists/src/split_import.rs b/crates/ra_assists/src/split_import.rs
index a8feb67c8..2c1edddb9 100644
--- a/crates/ra_assists/src/split_import.rs
+++ b/crates/ra_assists/src/split_import.rs
@@ -15,14 +15,14 @@ pub(crate) fn split_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
15 return None; 15 return None;
16 } 16 }
17 17
18 let l_curly = colon_colon.range().end(); 18 let l_curly = colon_colon.text_range().end();
19 let r_curly = match top_path.syntax().parent().and_then(ast::UseTree::cast) { 19 let r_curly = match top_path.syntax().parent().and_then(ast::UseTree::cast) {
20 Some(tree) => tree.syntax().range().end(), 20 Some(tree) => tree.syntax().text_range().end(),
21 None => top_path.syntax().range().end(), 21 None => top_path.syntax().text_range().end(),
22 }; 22 };
23 23
24 ctx.add_action(AssistId("split_import"), "split import", |edit| { 24 ctx.add_action(AssistId("split_import"), "split import", |edit| {
25 edit.target(colon_colon.range()); 25 edit.target(colon_colon.text_range());
26 edit.insert(l_curly, "{"); 26 edit.insert(l_curly, "{");
27 edit.insert(r_curly, "}"); 27 edit.insert(r_curly, "}");
28 edit.set_cursor(l_curly + TextUnit::of_str("{")); 28 edit.set_cursor(l_curly + TextUnit::of_str("{"));