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_ide_api/src/display/short_label.rs | 7 ++++--- crates/ra_ide_api/src/folding_ranges.rs | 2 +- crates/ra_ide_api/src/join_lines.rs | 2 +- crates/ra_ide_api/src/typing.rs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs index f926f631f..be499e485 100644 --- a/crates/ra_ide_api/src/display/short_label.rs +++ b/crates/ra_ide_api/src/display/short_label.rs @@ -1,3 +1,5 @@ +use std::fmt::Write; + use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; pub(crate) trait ShortLabel { @@ -71,8 +73,7 @@ where let mut buf = short_label_from_node(node, prefix)?; if let Some(type_ref) = node.ascribed_type() { - buf.push_str(": "); - type_ref.syntax().text().push_to(&mut buf); + write!(buf, ": {}", type_ref.syntax()).unwrap(); } Some(buf) @@ -82,7 +83,7 @@ fn short_label_from_node(node: &T, label: &str) -> Option where T: NameOwner + VisibilityOwner, { - let mut buf = node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default(); + let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default(); buf.push_str(label); buf.push_str(node.name()?.text().as_str()); Some(buf) diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index 9699000db..571d1c595 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs @@ -31,7 +31,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { // Fold items that span multiple lines if let Some(kind) = fold_kind(element.kind()) { let is_multiline = match &element { - SyntaxElement::Node(node) => node.text().contains('\n'), + SyntaxElement::Node(node) => node.text().contains_char('\n'), SyntaxElement::Token(token) => token.text().contains('\n'), }; if is_multiline { diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index fa998ebe1..7f25f2108 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs @@ -13,7 +13,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { let range = if range.is_empty() { let syntax = file.syntax(); let text = syntax.text().slice(range.start()..); - let pos = match text.find('\n') { + let pos = match text.find_char('\n') { None => return TextEditBuilder::default().finish(), Some(pos) => pos, }; diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 1747a529e..5a1cbcc49 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs @@ -75,7 +75,7 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option { if expr_range.contains(eq_offset) && eq_offset != expr_range.start() { return None; } - if file.syntax().text().slice(eq_offset..expr_range.start()).contains('\n') { + if file.syntax().text().slice(eq_offset..expr_range.start()).contains_char('\n') { return None; } } else { -- cgit v1.2.3