From f604ff5b2f72a593e23953ed8be7e9cbeba5d287 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 4 Jan 2019 21:29:00 +0800 Subject: parse doc comment for items --- crates/ra_analysis/src/lib.rs | 2 +- crates/ra_analysis/tests/test/main.rs | 3 ++- crates/ra_syntax/src/ast.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index ab935954c..1e26a2889 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -394,7 +394,7 @@ impl Analysis { pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable> { self.db.doc_text_for(nav) } - /// Returns a `mod name;` declaration whihc created the current module. + /// Returns a `mod name;` declaration which created the current module. pub fn parent_module(&self, position: FilePosition) -> Cancelable> { self.db.parent_module(position) } diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs index bfdf8aef2..859778024 100644 --- a/crates/ra_analysis/tests/test/main.rs +++ b/crates/ra_analysis/tests/test/main.rs @@ -249,7 +249,8 @@ fn bar() { fn test_fn_signature_with_docs_simple() { let (desc, param) = get_signature( r#" -// test +/// test +// non-doc-comment fn foo(j: u32) -> u32 { j } diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index e968c9728..c5273a7a2 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> { /// That is, strips leading `///` and joins lines fn doc_comment_text(self) -> RustString { self.doc_comments() + .filter(|comment| comment.is_doc_comment()) .map(|comment| { let prefix = comment.prefix(); let trimmed = comment @@ -206,6 +207,10 @@ impl<'a> Comment<'a> { } } + pub fn is_doc_comment(&self) -> bool { + self.flavor().is_doc_comment() + } + pub fn prefix(&self) -> &'static str { self.flavor().prefix() } @@ -237,6 +242,13 @@ impl CommentFlavor { Multiline => "/*", } } + + pub fn is_doc_comment(&self) -> bool { + match self { + CommentFlavor::Doc | CommentFlavor::ModuleDoc => true, + _ => false, + } + } } impl<'a> Whitespace<'a> { -- cgit v1.2.3