diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-17 16:00:43 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-17 16:00:43 +0000 |
commit | edf11480ceae1ef77d7084604011c0ef6f692c72 (patch) | |
tree | 6d1da24b8e275d8e36a12a48e1cdc9de0f8e1ec4 /crates/syntax/src/ast.rs | |
parent | baa19991688c6bdd99b63b8dc6f539be44da0350 (diff) | |
parent | 5734b347ddfff0d285d3eecf5735cac30271696c (diff) |
Merge #8065
8065: Better handling of block doc comments r=Veykril a=Veykril
Moves doc string processing to `Attrs::docs`, as we need the indent info from all comments before being able to know how much to strip
Closes #7774
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/syntax/src/ast.rs')
-rw-r--r-- | crates/syntax/src/ast.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs index 19261686c..38e0b04ef 100644 --- a/crates/syntax/src/ast.rs +++ b/crates/syntax/src/ast.rs | |||
@@ -118,7 +118,7 @@ fn test_doc_comment_none() { | |||
118 | .ok() | 118 | .ok() |
119 | .unwrap(); | 119 | .unwrap(); |
120 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 120 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
121 | assert!(module.doc_comment_text().is_none()); | 121 | assert!(module.doc_comments().doc_comment_text().is_none()); |
122 | } | 122 | } |
123 | 123 | ||
124 | #[test] | 124 | #[test] |
@@ -133,7 +133,7 @@ fn test_outer_doc_comment_of_items() { | |||
133 | .ok() | 133 | .ok() |
134 | .unwrap(); | 134 | .unwrap(); |
135 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 135 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
136 | assert_eq!("doc", module.doc_comment_text().unwrap()); | 136 | assert_eq!(" doc", module.doc_comments().doc_comment_text().unwrap()); |
137 | } | 137 | } |
138 | 138 | ||
139 | #[test] | 139 | #[test] |
@@ -148,7 +148,7 @@ fn test_inner_doc_comment_of_items() { | |||
148 | .ok() | 148 | .ok() |
149 | .unwrap(); | 149 | .unwrap(); |
150 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 150 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
151 | assert!(module.doc_comment_text().is_none()); | 151 | assert!(module.doc_comments().doc_comment_text().is_none()); |
152 | } | 152 | } |
153 | 153 | ||
154 | #[test] | 154 | #[test] |
@@ -162,7 +162,7 @@ fn test_doc_comment_of_statics() { | |||
162 | .ok() | 162 | .ok() |
163 | .unwrap(); | 163 | .unwrap(); |
164 | let st = file.syntax().descendants().find_map(Static::cast).unwrap(); | 164 | let st = file.syntax().descendants().find_map(Static::cast).unwrap(); |
165 | assert_eq!("Number of levels", st.doc_comment_text().unwrap()); | 165 | assert_eq!(" Number of levels", st.doc_comments().doc_comment_text().unwrap()); |
166 | } | 166 | } |
167 | 167 | ||
168 | #[test] | 168 | #[test] |
@@ -181,7 +181,10 @@ fn test_doc_comment_preserves_indents() { | |||
181 | .ok() | 181 | .ok() |
182 | .unwrap(); | 182 | .unwrap(); |
183 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 183 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
184 | assert_eq!("doc1\n```\nfn foo() {\n // ...\n}\n```", module.doc_comment_text().unwrap()); | 184 | assert_eq!( |
185 | " doc1\n ```\n fn foo() {\n // ...\n }\n ```", | ||
186 | module.doc_comments().doc_comment_text().unwrap() | ||
187 | ); | ||
185 | } | 188 | } |
186 | 189 | ||
187 | #[test] | 190 | #[test] |
@@ -198,7 +201,7 @@ fn test_doc_comment_preserves_newlines() { | |||
198 | .ok() | 201 | .ok() |
199 | .unwrap(); | 202 | .unwrap(); |
200 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 203 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
201 | assert_eq!("this\nis\nmod\nfoo", module.doc_comment_text().unwrap()); | 204 | assert_eq!(" this\n is\n mod\n foo", module.doc_comments().doc_comment_text().unwrap()); |
202 | } | 205 | } |
203 | 206 | ||
204 | #[test] | 207 | #[test] |
@@ -212,7 +215,7 @@ fn test_doc_comment_single_line_block_strips_suffix() { | |||
212 | .ok() | 215 | .ok() |
213 | .unwrap(); | 216 | .unwrap(); |
214 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 217 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
215 | assert_eq!("this is mod foo", module.doc_comment_text().unwrap()); | 218 | assert_eq!(" this is mod foo", module.doc_comments().doc_comment_text().unwrap()); |
216 | } | 219 | } |
217 | 220 | ||
218 | #[test] | 221 | #[test] |
@@ -226,7 +229,7 @@ fn test_doc_comment_single_line_block_strips_suffix_whitespace() { | |||
226 | .ok() | 229 | .ok() |
227 | .unwrap(); | 230 | .unwrap(); |
228 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 231 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
229 | assert_eq!("this is mod foo ", module.doc_comment_text().unwrap()); | 232 | assert_eq!(" this is mod foo ", module.doc_comments().doc_comment_text().unwrap()); |
230 | } | 233 | } |
231 | 234 | ||
232 | #[test] | 235 | #[test] |
@@ -245,8 +248,8 @@ fn test_doc_comment_multi_line_block_strips_suffix() { | |||
245 | .unwrap(); | 248 | .unwrap(); |
246 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 249 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
247 | assert_eq!( | 250 | assert_eq!( |
248 | " this\n is\n mod foo\n ", | 251 | "\n this\n is\n mod foo\n ", |
249 | module.doc_comment_text().unwrap() | 252 | module.doc_comments().doc_comment_text().unwrap() |
250 | ); | 253 | ); |
251 | } | 254 | } |
252 | 255 | ||
@@ -259,8 +262,8 @@ fn test_comments_preserve_trailing_whitespace() { | |||
259 | .unwrap(); | 262 | .unwrap(); |
260 | let def = file.syntax().descendants().find_map(Struct::cast).unwrap(); | 263 | let def = file.syntax().descendants().find_map(Struct::cast).unwrap(); |
261 | assert_eq!( | 264 | assert_eq!( |
262 | "Representation of a Realm. \nIn the specification these are called Realm Records.", | 265 | " Representation of a Realm. \n In the specification these are called Realm Records.", |
263 | def.doc_comment_text().unwrap() | 266 | def.doc_comments().doc_comment_text().unwrap() |
264 | ); | 267 | ); |
265 | } | 268 | } |
266 | 269 | ||
@@ -276,7 +279,7 @@ fn test_four_slash_line_comment() { | |||
276 | .ok() | 279 | .ok() |
277 | .unwrap(); | 280 | .unwrap(); |
278 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | 281 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); |
279 | assert_eq!("doc comment", module.doc_comment_text().unwrap()); | 282 | assert_eq!(" doc comment", module.doc_comments().doc_comment_text().unwrap()); |
280 | } | 283 | } |
281 | 284 | ||
282 | #[test] | 285 | #[test] |