From f6bcc2d7459a3e10090391a6f9b9a2789e9cab55 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Jul 2019 16:52:11 +0300 Subject: align SyntaxText API with upstream --- crates/ra_assists/src/add_impl.rs | 4 +++- crates/ra_assists/src/ast_editor.rs | 2 +- crates/ra_assists/src/introduce_variable.rs | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists') 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 @@ +use std::fmt::Write; + use hir::db::HirDatabase; use join_to_string::join; use ra_syntax::{ @@ -17,7 +19,7 @@ pub(crate) fn add_impl(mut ctx: AssistCtx) -> Option { let mut buf = String::new(); buf.push_str("\n\nimpl"); if let Some(type_params) = &type_params { - type_params.syntax().text().push_to(&mut buf); + write!(buf, "{}", type_params.syntax()).unwrap(); } buf.push_str(" "); 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 { position: InsertPosition<&'_ ast::NamedField>, field: &ast::NamedField, ) { - let is_multiline = self.ast().syntax().text().contains('\n'); + let is_multiline = self.ast().syntax().text().contains_char('\n'); let ws; let space = if is_multiline { 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 @@ +use std::fmt::Write; + use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode}, @@ -35,8 +37,7 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx) -> Option buf.push_str("let var_name = "); TextUnit::of_str("let ") }; - - expr.syntax().text().push_to(&mut buf); + write!(buf, "{}", expr.syntax()).unwrap(); let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); let is_full_stmt = if let Some(expr_stmt) = &full_stmt { Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone()) -- cgit v1.2.3