diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-04 13:52:47 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-04 13:52:47 +0000 |
commit | 821fa7a50ab8c4886adc60a2093aa8e06cc3a9d6 (patch) | |
tree | 6b23591e5a58341ff7696d8e3f90ecdf4c30ca2c /crates/ra_syntax/src | |
parent | 6295bbe6ec9741538307cd619ada1c9566f99a5d (diff) | |
parent | a0ef196d0404cf89367928f347dd515ba31d081b (diff) |
Merge #424
424: remove non-doc comments from doc comments r=matklad a=csmoe
Closes #357
Co-authored-by: csmoe <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index e968c9728..3aaa5edda 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -115,6 +115,7 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> { | |||
115 | /// That is, strips leading `///` and joins lines | 115 | /// That is, strips leading `///` and joins lines |
116 | fn doc_comment_text(self) -> RustString { | 116 | fn doc_comment_text(self) -> RustString { |
117 | self.doc_comments() | 117 | self.doc_comments() |
118 | .filter(|comment| comment.is_doc_comment()) | ||
118 | .map(|comment| { | 119 | .map(|comment| { |
119 | let prefix = comment.prefix(); | 120 | let prefix = comment.prefix(); |
120 | let trimmed = comment | 121 | let trimmed = comment |
@@ -206,6 +207,10 @@ impl<'a> Comment<'a> { | |||
206 | } | 207 | } |
207 | } | 208 | } |
208 | 209 | ||
210 | pub fn is_doc_comment(&self) -> bool { | ||
211 | self.flavor().is_doc_comment() | ||
212 | } | ||
213 | |||
209 | pub fn prefix(&self) -> &'static str { | 214 | pub fn prefix(&self) -> &'static str { |
210 | self.flavor().prefix() | 215 | self.flavor().prefix() |
211 | } | 216 | } |
@@ -237,6 +242,13 @@ impl CommentFlavor { | |||
237 | Multiline => "/*", | 242 | Multiline => "/*", |
238 | } | 243 | } |
239 | } | 244 | } |
245 | |||
246 | pub fn is_doc_comment(&self) -> bool { | ||
247 | match self { | ||
248 | CommentFlavor::Doc | CommentFlavor::ModuleDoc => true, | ||
249 | _ => false, | ||
250 | } | ||
251 | } | ||
240 | } | 252 | } |
241 | 253 | ||
242 | impl<'a> Whitespace<'a> { | 254 | impl<'a> Whitespace<'a> { |
@@ -469,3 +481,16 @@ impl<'a> PrefixExpr<'a> { | |||
469 | } | 481 | } |
470 | } | 482 | } |
471 | } | 483 | } |
484 | |||
485 | #[test] | ||
486 | fn test_doc_comment_of_items() { | ||
487 | let file = SourceFileNode::parse( | ||
488 | r#" | ||
489 | //! doc | ||
490 | // non-doc | ||
491 | mod foo {} | ||
492 | "#, | ||
493 | ); | ||
494 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
495 | assert_eq!("doc", module.doc_comment_text()); | ||
496 | } | ||