aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-30 20:57:33 +0000
committerJeremy A. Kolb <[email protected]>2018-10-31 19:08:37 +0000
commitd2bcd1a38636a669d2232156fa29010a82e37a3e (patch)
tree3a79a51afa0a15fc0a8251fe71f60f938d6822f0
parent64ce895ef0beea75e9ecfcdf5b4e226a8a6336d8 (diff)
`ast::DocCommentsOwner` which represents a documentation comment owner
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1
-rw-r--r--crates/ra_syntax/src/ast/mod.rs18
-rw-r--r--crates/ra_syntax/src/grammar.ron1
3 files changed, 20 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index d0cd060d3..b6a15dbdc 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -864,6 +864,7 @@ impl<'a> AstNode<'a> for FnDef<'a> {
864impl<'a> ast::NameOwner<'a> for FnDef<'a> {} 864impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
865impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} 865impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
866impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} 866impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
867impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {}
867impl<'a> FnDef<'a> { 868impl<'a> FnDef<'a> {
868 pub fn param_list(self) -> Option<ParamList<'a>> { 869 pub fn param_list(self) -> Option<ParamList<'a>> {
869 super::child_opt(self) 870 super::child_opt(self)
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs
index c033263a1..3aa11b9dd 100644
--- a/crates/ra_syntax/src/ast/mod.rs
+++ b/crates/ra_syntax/src/ast/mod.rs
@@ -65,6 +65,24 @@ pub trait AttrsOwner<'a>: AstNode<'a> {
65 } 65 }
66} 66}
67 67
68pub trait DocCommentsOwner<'a>: AstNode<'a> {
69 fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { children(self) }
70
71 /// Returns the textual content of a doc comment block as a single string.
72 /// That is, strips leading `///` and joins lines
73 fn doc_comment_text(self) -> String {
74 self.doc_comments()
75 .map(|comment| {
76 let prefix = comment.prefix();
77 let trimmed = comment.text().as_str()
78 .trim()
79 .trim_start_matches(prefix)
80 .trim_start();
81 trimmed.to_owned()
82 }).join("\n")
83 }
84}
85
68impl<'a> FnDef<'a> { 86impl<'a> FnDef<'a> {
69 pub fn has_atom_attr(&self, atom: &str) -> bool { 87 pub fn has_atom_attr(&self, atom: &str) -> bool {
70 self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom) 88 self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom)
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index c1c215e0d..6951db010 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -251,6 +251,7 @@ Grammar(
251 "NameOwner", 251 "NameOwner",
252 "TypeParamsOwner", 252 "TypeParamsOwner",
253 "AttrsOwner", 253 "AttrsOwner",
254 "DocCommentsOwner"
254 ], 255 ],
255 options: [ "ParamList", ["body", "Block"], "RetType" ], 256 options: [ "ParamList", ["body", "Block"], "RetType" ],
256 ), 257 ),