mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
align SyntaxText API with upstream
This commit is contained in:
parent
6b352ffeb3
commit
f6bcc2d745
9 changed files with 18 additions and 24 deletions
|
@ -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<T>(node: &T, label: &str) -> Option<String>
|
|||
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)
|
||||
|
|
|
@ -31,7 +31,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
|
|||
// 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 {
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option<TextEdit> {
|
|||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue