aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/lib.rs2
-rw-r--r--crates/ra_analysis/tests/test/main.rs3
-rw-r--r--crates/ra_syntax/src/ast.rs25
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0037_mod.rs5
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0037_mod.txt17
5 files changed, 50 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 {
394 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { 394 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
395 self.db.doc_text_for(nav) 395 self.db.doc_text_for(nav)
396 } 396 }
397 /// Returns a `mod name;` declaration whihc created the current module. 397 /// Returns a `mod name;` declaration which created the current module.
398 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { 398 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
399 self.db.parent_module(position) 399 self.db.parent_module(position)
400 } 400 }
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() {
249fn test_fn_signature_with_docs_simple() { 249fn test_fn_signature_with_docs_simple() {
250 let (desc, param) = get_signature( 250 let (desc, param) = get_signature(
251 r#" 251 r#"
252// test 252/// test
253// non-doc-comment
253fn foo(j: u32) -> u32 { 254fn foo(j: u32) -> u32 {
254 j 255 j
255} 256}
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
242impl<'a> Whitespace<'a> { 254impl<'a> Whitespace<'a> {
@@ -469,3 +481,16 @@ impl<'a> PrefixExpr<'a> {
469 } 481 }
470 } 482 }
471} 483}
484
485#[test]
486fn 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}
diff --git a/crates/ra_syntax/tests/data/parser/ok/0037_mod.rs b/crates/ra_syntax/tests/data/parser/ok/0037_mod.rs
new file mode 100644
index 000000000..7e5a1b835
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/ok/0037_mod.rs
@@ -0,0 +1,5 @@
1// https://github.com/rust-analyzer/rust-analyzer/issues/357
2
3//! docs
4// non-docs
5mod foo {} \ No newline at end of file
diff --git a/crates/ra_syntax/tests/data/parser/ok/0037_mod.txt b/crates/ra_syntax/tests/data/parser/ok/0037_mod.txt
new file mode 100644
index 000000000..e11c4a06d
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/ok/0037_mod.txt
@@ -0,0 +1,17 @@
1SOURCE_FILE@[0; 93)
2 COMMENT@[0; 60)
3 WHITESPACE@[60; 62)
4 MODULE@[62; 93)
5 COMMENT@[62; 70)
6 WHITESPACE@[70; 71)
7 COMMENT@[71; 82)
8 WHITESPACE@[82; 83)
9 MOD_KW@[83; 86)
10 WHITESPACE@[86; 87)
11 NAME@[87; 90)
12 IDENT@[87; 90) "foo"
13 WHITESPACE@[90; 91)
14 ITEM_LIST@[91; 93)
15 L_CURLY@[91; 92)
16 R_CURLY@[92; 93)
17