aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-20 14:52:11 +0100
committerAleksey Kladov <[email protected]>2019-07-20 14:52:11 +0100
commitf6bcc2d7459a3e10090391a6f9b9a2789e9cab55 (patch)
tree742f34cb6e1e38f1e009c23405fc2d3c6a232f72 /crates/ra_assists/src
parent6b352ffeb346eb7c7e46e00e790c2f395907eaa6 (diff)
align SyntaxText API with upstream
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/add_impl.rs4
-rw-r--r--crates/ra_assists/src/ast_editor.rs2
-rw-r--r--crates/ra_assists/src/introduce_variable.rs5
3 files changed, 7 insertions, 4 deletions
diff --git a/crates/ra_assists/src/add_impl.rs b/crates/ra_assists/src/add_impl.rs
index 9a0cfb4e7..59ca88468 100644
--- a/crates/ra_assists/src/add_impl.rs
+++ b/crates/ra_assists/src/add_impl.rs
@@ -1,3 +1,5 @@
1use std::fmt::Write;
2
1use hir::db::HirDatabase; 3use hir::db::HirDatabase;
2use join_to_string::join; 4use join_to_string::join;
3use ra_syntax::{ 5use ra_syntax::{
@@ -17,7 +19,7 @@ pub(crate) fn add_impl(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
17 let mut buf = String::new(); 19 let mut buf = String::new();
18 buf.push_str("\n\nimpl"); 20 buf.push_str("\n\nimpl");
19 if let Some(type_params) = &type_params { 21 if let Some(type_params) = &type_params {
20 type_params.syntax().text().push_to(&mut buf); 22 write!(buf, "{}", type_params.syntax()).unwrap();
21 } 23 }
22 buf.push_str(" "); 24 buf.push_str(" ");
23 buf.push_str(name.text().as_str()); 25 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 36235eb13..ab6c347ad 100644
--- a/crates/ra_assists/src/ast_editor.rs
+++ b/crates/ra_assists/src/ast_editor.rs
@@ -95,7 +95,7 @@ impl AstEditor<ast::NamedFieldList> {
95 position: InsertPosition<&'_ ast::NamedField>, 95 position: InsertPosition<&'_ ast::NamedField>,
96 field: &ast::NamedField, 96 field: &ast::NamedField,
97 ) { 97 ) {
98 let is_multiline = self.ast().syntax().text().contains('\n'); 98 let is_multiline = self.ast().syntax().text().contains_char('\n');
99 let ws; 99 let ws;
100 let space = if is_multiline { 100 let space = if is_multiline {
101 ws = tokens::WsBuilder::new(&format!( 101 ws = tokens::WsBuilder::new(&format!(
diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs
index df6c58989..911de2d48 100644
--- a/crates/ra_assists/src/introduce_variable.rs
+++ b/crates/ra_assists/src/introduce_variable.rs
@@ -1,3 +1,5 @@
1use std::fmt::Write;
2
1use hir::db::HirDatabase; 3use hir::db::HirDatabase;
2use ra_syntax::{ 4use ra_syntax::{
3 ast::{self, AstNode}, 5 ast::{self, AstNode},
@@ -35,8 +37,7 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option
35 buf.push_str("let var_name = "); 37 buf.push_str("let var_name = ");
36 TextUnit::of_str("let ") 38 TextUnit::of_str("let ")
37 }; 39 };
38 40 write!(buf, "{}", expr.syntax()).unwrap();
39 expr.syntax().text().push_to(&mut buf);
40 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); 41 let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone());
41 let is_full_stmt = if let Some(expr_stmt) = &full_stmt { 42 let is_full_stmt = if let Some(expr_stmt) = &full_stmt {
42 Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone()) 43 Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone())