aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r--crates/ra_syntax/src/ast.rs37
1 files changed, 10 insertions, 27 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index d6237532b..cf5cfecc2 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -127,16 +127,12 @@ pub trait DocCommentsOwner: AstNode {
127 let line = comment.text().as_str(); 127 let line = comment.text().as_str();
128 128
129 // Determine if the prefix or prefix + 1 char is stripped 129 // Determine if the prefix or prefix + 1 char is stripped
130 let pos = if line 130 let pos =
131 .chars() 131 if line.chars().nth(prefix_len).map(|c| c.is_whitespace()).unwrap_or(false) {
132 .nth(prefix_len) 132 prefix_len + 1
133 .map(|c| c.is_whitespace()) 133 } else {
134 .unwrap_or(false) 134 prefix_len
135 { 135 };
136 prefix_len + 1
137 } else {
138 prefix_len
139 };
140 136
141 line[pos..].to_owned() 137 line[pos..].to_owned()
142 }) 138 })
@@ -357,10 +353,7 @@ pub enum PathSegmentKind<'a> {
357 353
358impl PathSegment { 354impl PathSegment {
359 pub fn parent_path(&self) -> &Path { 355 pub fn parent_path(&self) -> &Path {
360 self.syntax() 356 self.syntax().parent().and_then(Path::cast).expect("segments are always nested in paths")
361 .parent()
362 .and_then(Path::cast)
363 .expect("segments are always nested in paths")
364 } 357 }
365 358
366 pub fn kind(&self) -> Option<PathSegmentKind> { 359 pub fn kind(&self) -> Option<PathSegmentKind> {
@@ -428,10 +421,7 @@ pub struct AstChildren<'a, N> {
428 421
429impl<'a, N> AstChildren<'a, N> { 422impl<'a, N> AstChildren<'a, N> {
430 fn new(parent: &'a SyntaxNode) -> Self { 423 fn new(parent: &'a SyntaxNode) -> Self {
431 AstChildren { 424 AstChildren { inner: parent.children(), ph: PhantomData }
432 inner: parent.children(),
433 ph: PhantomData,
434 }
435 } 425 }
436} 426}
437 427
@@ -658,11 +648,7 @@ impl SelfParam {
658 let borrowed = self.syntax().children().any(|n| n.kind() == AMP); 648 let borrowed = self.syntax().children().any(|n| n.kind() == AMP);
659 if borrowed { 649 if borrowed {
660 // check for a `mut` coming after the & -- `mut &self` != `&mut self` 650 // check for a `mut` coming after the & -- `mut &self` != `&mut self`
661 if self 651 if self.syntax().children().skip_while(|n| n.kind() != AMP).any(|n| n.kind() == MUT_KW)
662 .syntax()
663 .children()
664 .skip_while(|n| n.kind() != AMP)
665 .any(|n| n.kind() == MUT_KW)
666 { 652 {
667 SelfParamFlavor::MutRef 653 SelfParamFlavor::MutRef
668 } else { 654 } else {
@@ -769,8 +755,5 @@ fn test_doc_comment_preserves_indents() {
769 "#, 755 "#,
770 ); 756 );
771 let module = file.syntax().descendants().find_map(Module::cast).unwrap(); 757 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
772 assert_eq!( 758 assert_eq!("doc1\n```\nfn foo() {\n // ...\n}\n```", module.doc_comment_text().unwrap());
773 "doc1\n```\nfn foo() {\n // ...\n}\n```",
774 module.doc_comment_text().unwrap()
775 );
776} 759}