mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Cleanup fold code and split logic to fold single elements
This commit is contained in:
parent
ee0a6bf053
commit
4b3737510b
4 changed files with 115 additions and 43 deletions
|
@ -100,8 +100,8 @@ impl<'a> Lifetime<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Comment<'a> {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
self.syntax().leaf_text().unwrap().clone()
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
self.syntax().leaf_text().unwrap()
|
||||
}
|
||||
|
||||
pub fn flavor(&self) -> CommentFlavor {
|
||||
|
@ -120,6 +120,14 @@ impl<'a> Comment<'a> {
|
|||
pub fn prefix(&self) -> &'static str {
|
||||
self.flavor().prefix()
|
||||
}
|
||||
|
||||
pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> {
|
||||
self.text().chars().filter(|&c| c == '\n').map(|_| &())
|
||||
}
|
||||
|
||||
pub fn has_newlines(&self) -> bool {
|
||||
self.count_newlines_lazy().count() > 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -142,6 +150,20 @@ impl CommentFlavor {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Whitespace<'a> {
|
||||
pub fn text(&self) -> &SmolStr {
|
||||
&self.syntax().leaf_text().unwrap()
|
||||
}
|
||||
|
||||
pub fn count_newlines_lazy(&self) -> impl Iterator<Item = &()> {
|
||||
self.text().chars().filter(|&c| c == '\n').map(|_| &())
|
||||
}
|
||||
|
||||
pub fn has_newlines(&self) -> bool {
|
||||
self.count_newlines_lazy().count() > 0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Name<'a> {
|
||||
pub fn text(&self) -> SmolStr {
|
||||
let ident = self.syntax().first_child()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue