mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
.
This commit is contained in:
parent
63f509f492
commit
46b4f89c92
28 changed files with 69 additions and 67 deletions
|
@ -495,7 +495,7 @@ pub mod tokens {
|
|||
.syntax()
|
||||
.descendants_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == WHITESPACE && it.text().as_str() == " ")
|
||||
.find(|it| it.kind() == WHITESPACE && it.text() == " ")
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
@ -523,7 +523,7 @@ pub mod tokens {
|
|||
.syntax()
|
||||
.descendants_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == WHITESPACE && it.text().as_str() == "\n")
|
||||
.find(|it| it.kind() == WHITESPACE && it.text() == "\n")
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
@ -533,7 +533,7 @@ pub mod tokens {
|
|||
.syntax()
|
||||
.descendants_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == WHITESPACE && it.text().as_str() == "\n\n")
|
||||
.find(|it| it.kind() == WHITESPACE && it.text() == "\n\n")
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,19 +13,19 @@ use crate::{
|
|||
};
|
||||
|
||||
impl ast::Lifetime {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
pub fn text(&self) -> &str {
|
||||
text_of_first_token(self.syntax())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Name {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
pub fn text(&self) -> &str {
|
||||
text_of_first_token(self.syntax())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::NameRef {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
pub fn text(&self) -> &str {
|
||||
text_of_first_token(self.syntax())
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ impl ast::NameRef {
|
|||
}
|
||||
}
|
||||
|
||||
fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {
|
||||
fn text_of_first_token(node: &SyntaxNode) -> &str {
|
||||
node.green().children().next().and_then(|it| it.into_token()).unwrap().text()
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ impl ast::Attr {
|
|||
pub fn simple_name(&self) -> Option<SmolStr> {
|
||||
let path = self.path()?;
|
||||
match (path.segment(), path.qualifier()) {
|
||||
(Some(segment), None) => Some(segment.syntax().first_token()?.text().clone()),
|
||||
(Some(segment), None) => Some(segment.syntax().first_token()?.text().into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ impl ast::Comment {
|
|||
match kind {
|
||||
CommentKind { shape, doc: Some(_) } => {
|
||||
let prefix = kind.prefix();
|
||||
let text = &self.text().as_str()[prefix.len()..];
|
||||
let text = &self.text()[prefix.len()..];
|
||||
let ws = text.chars().next().filter(|c| c.is_whitespace());
|
||||
let text = ws.map_or(text, |ws| &text[ws.len_utf8()..]);
|
||||
match shape {
|
||||
|
@ -156,13 +156,13 @@ impl ast::String {
|
|||
|
||||
pub fn value(&self) -> Option<Cow<'_, str>> {
|
||||
if self.is_raw() {
|
||||
let text = self.text().as_str();
|
||||
let text = self.text();
|
||||
let text =
|
||||
&text[self.text_range_between_quotes()? - self.syntax().text_range().start()];
|
||||
return Some(Cow::Borrowed(text));
|
||||
}
|
||||
|
||||
let text = self.text().as_str();
|
||||
let text = self.text();
|
||||
let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()];
|
||||
|
||||
let mut buf = String::new();
|
||||
|
@ -190,7 +190,7 @@ impl ast::String {
|
|||
}
|
||||
|
||||
pub fn quote_offsets(&self) -> Option<QuoteOffsets> {
|
||||
let text = self.text().as_str();
|
||||
let text = self.text();
|
||||
let offsets = QuoteOffsets::new(text)?;
|
||||
let o = self.syntax().text_range().start();
|
||||
let offsets = QuoteOffsets {
|
||||
|
@ -560,7 +560,7 @@ impl HasFormatSpecifier for ast::String {
|
|||
fn char_ranges(
|
||||
&self,
|
||||
) -> Option<Vec<(TextRange, Result<char, rustc_lexer::unescape::EscapeError>)>> {
|
||||
let text = self.text().as_str();
|
||||
let text = self.text();
|
||||
let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()];
|
||||
let offset = self.text_range_between_quotes()?.start() - self.syntax().text_range().start();
|
||||
|
||||
|
@ -590,7 +590,7 @@ impl ast::IntNumber {
|
|||
pub fn value(&self) -> Option<u128> {
|
||||
let token = self.syntax();
|
||||
|
||||
let mut text = token.text().as_str();
|
||||
let mut text = token.text();
|
||||
if let Some(suffix) = self.suffix() {
|
||||
text = &text[..text.len() - suffix.len()]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue