aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/ast.rs24
-rw-r--r--crates/ra_syntax/src/ast/traits.rs7
2 files changed, 27 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 1b2ce921a..a12da5be2 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -173,7 +173,7 @@ fn test_doc_comment_single_line_block_strips_suffix_whitespace() {
173 .ok() 173 .ok()
174 .unwrap(); 174 .unwrap();
175 let module = file.syntax().descendants().find_map(Module::cast).unwrap(); 175 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
176 assert_eq!("this is mod foo", module.doc_comment_text().unwrap()); 176 assert_eq!("this is mod foo ", module.doc_comment_text().unwrap());
177} 177}
178 178
179#[test] 179#[test]
@@ -191,7 +191,27 @@ fn test_doc_comment_multi_line_block_strips_suffix() {
191 .ok() 191 .ok()
192 .unwrap(); 192 .unwrap();
193 let module = file.syntax().descendants().find_map(Module::cast).unwrap(); 193 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
194 assert_eq!(" this\n is\n mod foo", module.doc_comment_text().unwrap()); 194 assert_eq!(
195 " this\n is\n mod foo\n ",
196 module.doc_comment_text().unwrap()
197 );
198}
199
200#[test]
201fn test_comments_preserve_trailing_whitespace() {
202 let file = SourceFile::parse(
203 r#"
204/// Representation of a Realm.
205/// In the specification these are called Realm Records.
206struct Realm {}"#,
207 )
208 .ok()
209 .unwrap();
210 let def = file.syntax().descendants().find_map(StructDef::cast).unwrap();
211 assert_eq!(
212 "Representation of a Realm. \nIn the specification these are called Realm Records.",
213 def.doc_comment_text().unwrap()
214 );
195} 215}
196 216
197#[test] 217#[test]
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index f275a4955..76313684e 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -120,7 +120,7 @@ pub trait DocCommentsOwner: AstNode {
120 has_comments = true; 120 has_comments = true;
121 let prefix_len = comment.prefix().len(); 121 let prefix_len = comment.prefix().len();
122 122
123 let line = comment.text().as_str(); 123 let line: &str = comment.text().as_str();
124 124
125 // Determine if the prefix or prefix + 1 char is stripped 125 // Determine if the prefix or prefix + 1 char is stripped
126 let pos = 126 let pos =
@@ -136,7 +136,10 @@ pub trait DocCommentsOwner: AstNode {
136 line.len() 136 line.len()
137 }; 137 };
138 138
139 line[pos..end].trim_end().to_owned() 139 // Note that we do not trim the end of the line here
140 // since whitespace can have special meaning at the end
141 // of a line in markdown.
142 line[pos..end].to_owned()
140 }) 143 })
141 .join("\n"); 144 .join("\n");
142 145