aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-20 18:04:34 +0100
committerAleksey Kladov <[email protected]>2019-07-20 18:12:06 +0100
commitc9cfd57eeaa53657c0af7b9c4ba74d6b7b9889ed (patch)
tree422c1d8fb7f8af663df3c6c6183783253692acad /crates/ra_assists/src
parent7bde8012cb28c44de7ffc779003781d385323808 (diff)
switch to upstream rowan's API
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/add_impl.rs5
-rw-r--r--crates/ra_assists/src/ast_editor.rs9
-rw-r--r--crates/ra_assists/src/introduce_variable.rs5
-rw-r--r--crates/ra_assists/src/move_guard.rs8
4 files changed, 14 insertions, 13 deletions
diff --git a/crates/ra_assists/src/add_impl.rs b/crates/ra_assists/src/add_impl.rs
index 59ca88468..4b61f4031 100644
--- a/crates/ra_assists/src/add_impl.rs
+++ b/crates/ra_assists/src/add_impl.rs
@@ -1,5 +1,4 @@
1use std::fmt::Write; 1use format_buf::format;
2
3use hir::db::HirDatabase; 2use hir::db::HirDatabase;
4use join_to_string::join; 3use join_to_string::join;
5use ra_syntax::{ 4use ra_syntax::{
@@ -19,7 +18,7 @@ pub(crate) fn add_impl(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
19 let mut buf = String::new(); 18 let mut buf = String::new();
20 buf.push_str("\n\nimpl"); 19 buf.push_str("\n\nimpl");
21 if let Some(type_params) = &type_params { 20 if let Some(type_params) = &type_params {
22 write!(buf, "{}", type_params.syntax()).unwrap(); 21 format!(buf, "{}", type_params.syntax());
23 } 22 }
24 buf.push_str(" "); 23 buf.push_str(" ");
25 buf.push_str(name.text().as_str()); 24 buf.push_str(name.text().as_str());
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs
index ab6c347ad..95b871b30 100644
--- a/crates/ra_assists/src/ast_editor.rs
+++ b/crates/ra_assists/src/ast_editor.rs
@@ -4,7 +4,10 @@ use arrayvec::ArrayVec;
4use hir::Name; 4use hir::Name;
5use ra_fmt::leading_indent; 5use ra_fmt::leading_indent;
6use ra_syntax::{ 6use ra_syntax::{
7 ast, AstNode, Direction, InsertPosition, SourceFile, SyntaxElement, SyntaxKind::*, T, 7 algo::{insert_children, replace_children},
8 ast, AstNode, Direction, InsertPosition, SourceFile, SyntaxElement,
9 SyntaxKind::*,
10 T,
8}; 11};
9use ra_text_edit::TextEditBuilder; 12use ra_text_edit::TextEditBuilder;
10 13
@@ -38,7 +41,7 @@ impl<N: AstNode> AstEditor<N> {
38 position: InsertPosition<SyntaxElement>, 41 position: InsertPosition<SyntaxElement>,
39 to_insert: impl Iterator<Item = SyntaxElement>, 42 to_insert: impl Iterator<Item = SyntaxElement>,
40 ) -> N { 43 ) -> N {
41 let new_syntax = self.ast().syntax().insert_children(position, to_insert); 44 let new_syntax = insert_children(self.ast().syntax(), position, to_insert);
42 N::cast(new_syntax).unwrap() 45 N::cast(new_syntax).unwrap()
43 } 46 }
44 47
@@ -48,7 +51,7 @@ impl<N: AstNode> AstEditor<N> {
48 to_delete: RangeInclusive<SyntaxElement>, 51 to_delete: RangeInclusive<SyntaxElement>,
49 to_insert: impl Iterator<Item = SyntaxElement>, 52 to_insert: impl Iterator<Item = SyntaxElement>,
50 ) -> N { 53 ) -> N {
51 let new_syntax = self.ast().syntax().replace_children(to_delete, to_insert); 54 let new_syntax = replace_children(self.ast().syntax(), to_delete, to_insert);
52 N::cast(new_syntax).unwrap() 55 N::cast(new_syntax).unwrap()
53 } 56 }
54 57
diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs
index 911de2d48..5eb708310 100644
--- a/crates/ra_assists/src/introduce_variable.rs
+++ b/crates/ra_assists/src/introduce_variable.rs
@@ -1,5 +1,4 @@
1use std::fmt::Write; 1use format_buf::format;
2
3use hir::db::HirDatabase; 2use hir::db::HirDatabase;
4use ra_syntax::{ 3use ra_syntax::{
5 ast::{self, AstNode}, 4 ast::{self, AstNode},
@@ -37,7 +36,7 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option
37 buf.push_str("let var_name = "); 36 buf.push_str("let var_name = ");
38 TextUnit::of_str("let ") 37 TextUnit::of_str("let ")
39 }; 38 };
40 write!(buf, "{}", expr.syntax()).unwrap(); 39 format!(buf, "{}", expr.syntax());
41 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); 40 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone());
42 let is_full_stmt = if let Some(expr_stmt) = &full_stmt { 41 let is_full_stmt = if let Some(expr_stmt) = &full_stmt {
43 Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone()) 42 Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone())
diff --git a/crates/ra_assists/src/move_guard.rs b/crates/ra_assists/src/move_guard.rs
index 0f3cdbe53..127c9e068 100644
--- a/crates/ra_assists/src/move_guard.rs
+++ b/crates/ra_assists/src/move_guard.rs
@@ -2,7 +2,7 @@ use hir::db::HirDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 ast, 3 ast,
4 ast::{AstNode, AstToken, IfExpr, MatchArm}, 4 ast::{AstNode, AstToken, IfExpr, MatchArm},
5 SyntaxElement, TextUnit, 5 TextUnit,
6}; 6};
7 7
8use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
@@ -18,10 +18,10 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Op
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().text_range()); 20 edit.target(guard.syntax().text_range());
21 let offseting_amount = match &space_before_guard { 21 let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) {
22 Some(SyntaxElement::Token(tok)) => { 22 Some(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().text_range(); 24 let ele = tok.text_range();
25 edit.delete(ele); 25 edit.delete(ele);
26 ele.len() 26 ele.len()
27 } else { 27 } else {