aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-03 20:25:30 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-03 20:25:30 +0100
commitc5bdd02503b782eb8406cfdb2692ef51c05d5f48 (patch)
treeb4ff935c1e82c06404daaf132b720ca033704b84
parente96c9e4865f392e1de7ef32e244151ad97b403dc (diff)
parent0f61aa1f09f0609271d3c0a3d23815488ec94949 (diff)
Merge #1630
1630: Removes `*/` from block doc comments r=matklad a=kjeremy The trailing `/` was annoying me on hover. Co-authored-by: kjeremy <[email protected]>
-rw-r--r--crates/ra_syntax/src/ast.rs46
-rw-r--r--crates/ra_syntax/src/ast/traits.rs12
2 files changed, 55 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index c5746d98d..6f0489617 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -139,6 +139,52 @@ fn test_doc_comment_preserves_newlines() {
139} 139}
140 140
141#[test] 141#[test]
142fn test_doc_comment_single_line_block_strips_suffix() {
143 let file = SourceFile::parse(
144 r#"
145 /** this is mod foo*/
146 mod foo {}
147 "#,
148 )
149 .ok()
150 .unwrap();
151 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
152 assert_eq!("this is mod foo", module.doc_comment_text().unwrap());
153}
154
155#[test]
156fn test_doc_comment_single_line_block_strips_suffix_whitespace() {
157 let file = SourceFile::parse(
158 r#"
159 /** this is mod foo */
160 mod foo {}
161 "#,
162 )
163 .ok()
164 .unwrap();
165 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
166 assert_eq!("this is mod foo", module.doc_comment_text().unwrap());
167}
168
169#[test]
170fn test_doc_comment_multi_line_block_strips_suffix() {
171 let file = SourceFile::parse(
172 r#"
173 /**
174 this
175 is
176 mod foo
177 */
178 mod foo {}
179 "#,
180 )
181 .ok()
182 .unwrap();
183 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
184 assert_eq!(" this\n is\n mod foo", module.doc_comment_text().unwrap());
185}
186
187#[test]
142fn test_where_predicates() { 188fn test_where_predicates() {
143 fn assert_bound(text: &str, bound: Option<TypeBound>) { 189 fn assert_bound(text: &str, bound: Option<TypeBound>) {
144 assert_eq!(text, bound.unwrap().syntax().text().to_string()); 190 assert_eq!(text, bound.unwrap().syntax().text().to_string());
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 6ed1b5213..1b9a2b20c 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -115,8 +115,8 @@ pub trait DocCommentsOwner: AstNode {
115 } 115 }
116 116
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 /// trailing `*/`, trailing whitespace and then joins the lines.
120 fn doc_comment_text(&self) -> Option<String> { 120 fn doc_comment_text(&self) -> Option<String> {
121 let mut has_comments = false; 121 let mut has_comments = false;
122 let docs = self 122 let docs = self
@@ -136,7 +136,13 @@ pub trait DocCommentsOwner: AstNode {
136 prefix_len 136 prefix_len
137 }; 137 };
138 138
139 line[pos..].to_owned() 139 let end = if comment.kind().shape.is_block() && line.ends_with("*/") {
140 line.len() - 2
141 } else {
142 line.len()
143 };
144
145 line[pos..end].trim_end().to_owned()
140 }) 146 })
141 .join("\n"); 147 .join("\n");
142 148