parse doc comment for items

This commit is contained in:
csmoe 2019-01-04 21:29:00 +08:00
parent 8a6d6ac132
commit f604ff5b2f
3 changed files with 15 additions and 2 deletions

View File

@ -394,7 +394,7 @@ pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, T
pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
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<Vec<NavigationTarget>> {
self.db.parent_module(position)
}

View File

@ -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
}

View File

@ -115,6 +115,7 @@ fn doc_comments(self) -> AstChildren<'a, Comment<'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 @@ pub fn flavor(&self) -> CommentFlavor {
}
}
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 @@ pub fn prefix(&self) -> &'static str {
Multiline => "/*",
}
}
pub fn is_doc_comment(&self) -> bool {
match self {
CommentFlavor::Doc | CommentFlavor::ModuleDoc => true,
_ => false,
}
}
}
impl<'a> Whitespace<'a> {