diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/docs.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 29 |
4 files changed, 27 insertions, 19 deletions
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index b1b47af9e..5db72c08a 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs | |||
@@ -27,10 +27,5 @@ pub trait Docs { | |||
27 | } | 27 | } |
28 | 28 | ||
29 | pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { | 29 | pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { |
30 | let comments = node.doc_comment_text(); | 30 | node.doc_comment_text().map(|it| Documentation::new(&it)) |
31 | if comments.is_empty() { | ||
32 | None | ||
33 | } else { | ||
34 | Some(Documentation::new(&comments)) | ||
35 | } | ||
36 | } | 31 | } |
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 3267fff96..7554c4aee 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -120,8 +120,7 @@ impl CallInfo { | |||
120 | }; | 120 | }; |
121 | 121 | ||
122 | let mut doc = None; | 122 | let mut doc = None; |
123 | let docs = node.doc_comment_text(); | 123 | if let Some(docs) = node.doc_comment_text() { |
124 | if !docs.is_empty() { | ||
125 | // Massage markdown | 124 | // Massage markdown |
126 | let mut processed_lines = Vec::new(); | 125 | let mut processed_lines = Vec::new(); |
127 | let mut in_code_block = false; | 126 | let mut in_code_block = false; |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index ff9ae2d9c..f993a461c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -100,12 +100,7 @@ impl NavigationTarget { | |||
100 | fn docs(&self, db: &RootDatabase) -> Option<String> { | 100 | fn docs(&self, db: &RootDatabase) -> Option<String> { |
101 | let node = self.node(db)?; | 101 | let node = self.node(db)?; |
102 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { | 102 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { |
103 | let comments = node.doc_comment_text(); | 103 | node.doc_comment_text() |
104 | if comments.is_empty() { | ||
105 | None | ||
106 | } else { | ||
107 | Some(comments) | ||
108 | } | ||
109 | } | 104 | } |
110 | 105 | ||
111 | visitor() | 106 | visitor() |
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index cdfb9c523..d59890d95 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -117,8 +117,9 @@ pub trait DocCommentsOwner: AstNode { | |||
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 | /// and joins lines. |
120 | fn doc_comment_text(&self) -> std::string::String { | 120 | fn doc_comment_text(&self) -> Option<std::string::String> { |
121 | self.doc_comments() | 121 | let docs = self |
122 | .doc_comments() | ||
122 | .filter(|comment| comment.is_doc_comment()) | 123 | .filter(|comment| comment.is_doc_comment()) |
123 | .map(|comment| { | 124 | .map(|comment| { |
124 | let prefix_len = comment.prefix().len(); | 125 | let prefix_len = comment.prefix().len(); |
@@ -139,7 +140,13 @@ pub trait DocCommentsOwner: AstNode { | |||
139 | 140 | ||
140 | line[pos..].to_owned() | 141 | line[pos..].to_owned() |
141 | }) | 142 | }) |
142 | .join("\n") | 143 | .join("\n"); |
144 | |||
145 | if docs.is_empty() { | ||
146 | None | ||
147 | } else { | ||
148 | Some(docs) | ||
149 | } | ||
143 | } | 150 | } |
144 | } | 151 | } |
145 | 152 | ||
@@ -700,6 +707,18 @@ impl BindPat { | |||
700 | } | 707 | } |
701 | 708 | ||
702 | #[test] | 709 | #[test] |
710 | fn test_doc_comment_none() { | ||
711 | let file = SourceFile::parse( | ||
712 | r#" | ||
713 | // non-doc | ||
714 | mod foo {} | ||
715 | "#, | ||
716 | ); | ||
717 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
718 | assert!(module.doc_comment_text().is_none()); | ||
719 | } | ||
720 | |||
721 | #[test] | ||
703 | fn test_doc_comment_of_items() { | 722 | fn test_doc_comment_of_items() { |
704 | let file = SourceFile::parse( | 723 | let file = SourceFile::parse( |
705 | r#" | 724 | r#" |
@@ -709,7 +728,7 @@ fn test_doc_comment_of_items() { | |||
709 | "#, | 728 | "#, |
710 | ); | 729 | ); |
711 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 730 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
712 | assert_eq!("doc", module.doc_comment_text()); | 731 | assert_eq!("doc", module.doc_comment_text().unwrap()); |
713 | } | 732 | } |
714 | 733 | ||
715 | #[test] | 734 | #[test] |
@@ -728,6 +747,6 @@ fn test_doc_comment_preserves_indents() { | |||
728 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 747 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
729 | assert_eq!( | 748 | assert_eq!( |
730 | "doc1\n```\nfn foo() {\n // ...\n}\n```", | 749 | "doc1\n```\nfn foo() {\n // ...\n}\n```", |
731 | module.doc_comment_text() | 750 | module.doc_comment_text().unwrap() |
732 | ); | 751 | ); |
733 | } | 752 | } |