aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/mod.rs')
-rw-r--r--crates/ra_syntax/src/ast/mod.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs
index d93f92672..7077e3492 100644
--- a/crates/ra_syntax/src/ast/mod.rs
+++ b/crates/ra_syntax/src/ast/mod.rs
@@ -1,6 +1,7 @@
1mod generated; 1mod generated;
2 2
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4use std::string::String as RustString;
4 5
5use itertools::Itertools; 6use itertools::Itertools;
6 7
@@ -76,7 +77,7 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> {
76 77
77 /// Returns the textual content of a doc comment block as a single string. 78 /// Returns the textual content of a doc comment block as a single string.
78 /// That is, strips leading `///` and joins lines 79 /// That is, strips leading `///` and joins lines
79 fn doc_comment_text(self) -> String { 80 fn doc_comment_text(self) -> RustString {
80 self.doc_comments() 81 self.doc_comments()
81 .map(|comment| { 82 .map(|comment| {
82 let prefix = comment.prefix(); 83 let prefix = comment.prefix();
@@ -133,6 +134,24 @@ impl<'a> Char<'a> {
133 } 134 }
134} 135}
135 136
137impl<'a> Byte<'a> {
138 pub fn text(&self) -> &SmolStr {
139 &self.syntax().leaf_text().unwrap()
140 }
141}
142
143impl<'a> ByteString<'a> {
144 pub fn text(&self) -> &SmolStr {
145 &self.syntax().leaf_text().unwrap()
146 }
147}
148
149impl<'a> String<'a> {
150 pub fn text(&self) -> &SmolStr {
151 &self.syntax().leaf_text().unwrap()
152 }
153}
154
136impl<'a> Comment<'a> { 155impl<'a> Comment<'a> {
137 pub fn text(&self) -> &SmolStr { 156 pub fn text(&self) -> &SmolStr {
138 self.syntax().leaf_text().unwrap() 157 self.syntax().leaf_text().unwrap()
@@ -296,6 +315,15 @@ impl<'a> PathSegment<'a> {
296 } 315 }
297} 316}
298 317
318impl<'a> UseTreeList<'a> {
319 pub fn parent_use_tree(self) -> UseTree<'a> {
320 self.syntax()
321 .parent()
322 .and_then(UseTree::cast)
323 .expect("UseTreeLists are always nested in UseTrees")
324 }
325}
326
299fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { 327fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> {
300 children(parent).next() 328 children(parent).next()
301} 329}