aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs10
-rw-r--r--crates/ra_syntax/src/ast/generated.rs2
-rw-r--r--crates/ra_syntax/src/ast/traits.rs12
3 files changed, 21 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index d4873b39a..2a59cf653 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -91,6 +91,7 @@ impl ast::Attr {
91#[derive(Debug, Clone, PartialEq, Eq)] 91#[derive(Debug, Clone, PartialEq, Eq)]
92pub enum PathSegmentKind { 92pub enum PathSegmentKind {
93 Name(ast::NameRef), 93 Name(ast::NameRef),
94 Type { type_ref: Option<ast::TypeRef>, trait_ref: Option<ast::PathType> },
94 SelfKw, 95 SelfKw,
95 SuperKw, 96 SuperKw,
96 CrateKw, 97 CrateKw,
@@ -112,6 +113,15 @@ impl ast::PathSegment {
112 T![self] => PathSegmentKind::SelfKw, 113 T![self] => PathSegmentKind::SelfKw,
113 T![super] => PathSegmentKind::SuperKw, 114 T![super] => PathSegmentKind::SuperKw,
114 T![crate] => PathSegmentKind::CrateKw, 115 T![crate] => PathSegmentKind::CrateKw,
116 T![<] => {
117 // <T> or <T as Trait>
118 // T is any TypeRef, Trait has to be a PathType
119 let mut type_refs =
120 self.syntax().children().filter(|node| ast::TypeRef::can_cast(node.kind()));
121 let type_ref = type_refs.next().and_then(ast::TypeRef::cast);
122 let trait_ref = type_refs.next().and_then(ast::PathType::cast);
123 PathSegmentKind::Type { type_ref, trait_ref }
124 }
115 _ => return None, 125 _ => return None,
116 } 126 }
117 }; 127 };
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index da8cf4ae8..f322e1d84 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -2013,6 +2013,7 @@ impl AstNode for Param {
2013 2013
2014 2014
2015impl ast::TypeAscriptionOwner for Param {} 2015impl ast::TypeAscriptionOwner for Param {}
2016impl ast::AttrsOwner for Param {}
2016impl Param { 2017impl Param {
2017 pub fn pat(&self) -> Option<Pat> { 2018 pub fn pat(&self) -> Option<Pat> {
2018 super::child_opt(self) 2019 super::child_opt(self)
@@ -2667,6 +2668,7 @@ impl AstNode for SelfParam {
2667 2668
2668 2669
2669impl ast::TypeAscriptionOwner for SelfParam {} 2670impl ast::TypeAscriptionOwner for SelfParam {}
2671impl ast::AttrsOwner for SelfParam {}
2670impl SelfParam {} 2672impl SelfParam {}
2671 2673
2672// SlicePat 2674// SlicePat
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 6ed1b5213..1b9a2b20c 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -115,8 +115,8 @@ pub trait DocCommentsOwner: AstNode {
115 } 115 }
116 116
117 /// Returns the textual content of a doc comment block as a single string. 117 /// Returns the textual content of a doc comment block as a single string.
118 /// That is, strips leading `///` (+ optional 1 character of whitespace) 118 /// That is, strips leading `///` (+ optional 1 character of whitespace),
119 /// and joins lines. 119 /// trailing `*/`, trailing whitespace and then joins the lines.
120 fn doc_comment_text(&self) -> Option<String> { 120 fn doc_comment_text(&self) -> Option<String> {
121 let mut has_comments = false; 121 let mut has_comments = false;
122 let docs = self 122 let docs = self
@@ -136,7 +136,13 @@ pub trait DocCommentsOwner: AstNode {
136 prefix_len 136 prefix_len
137 }; 137 };
138 138
139 line[pos..].to_owned() 139 let end = if comment.kind().shape.is_block() && line.ends_with("*/") {
140 line.len() - 2
141 } else {
142 line.len()
143 };
144
145 line[pos..end].trim_end().to_owned()
140 }) 146 })
141 .join("\n"); 147 .join("\n");
142 148