Preserve empty lines in doc comments.
This required two changes in parallel. As a first and obvious step it removes a check that skipped emptys lines during documentation loading, but it was also necessary to refactore the `get_comment_lines()` utility method as a second step. This second refactoring was necessary as each line in a doc comment is trimmed and transformed in its own doc attribute. The attribute of an empty line therefore contains an empty string as value. If we now call `lines()` on such an empty string we end up with an empty iterator as the method is internally configured to ignore trailing empty lines.
This commit is contained in:
committed by
Emilio Cobos Álvarez
parent
65fbb25638
commit
b4b82a500c
@@ -20,7 +20,7 @@ impl Documentation {
|
||||
let doc = attrs
|
||||
.get_comment_lines()
|
||||
.into_iter()
|
||||
.filter(|x| !x.is_empty() && !x.starts_with("cbindgen:"))
|
||||
.filter(|x| !x.starts_with("cbindgen:"))
|
||||
.collect();
|
||||
|
||||
Documentation { doc_comment: doc }
|
||||
|
||||
+19
-15
@@ -252,7 +252,7 @@ impl SynAttributeHelpers for [syn::Attribute] {
|
||||
}
|
||||
|
||||
fn get_comment_lines(&self) -> Vec<String> {
|
||||
let mut comment_lines = Vec::new();
|
||||
let mut raw_comment = String::new();
|
||||
|
||||
for attr in self {
|
||||
if attr.style == syn::AttrStyle::Outer {
|
||||
@@ -263,26 +263,30 @@ impl SynAttributeHelpers for [syn::Attribute] {
|
||||
})) = attr.interpret_meta()
|
||||
{
|
||||
let name = ident.to_string();
|
||||
let comment = comment.value();
|
||||
|
||||
if &*name == "doc" {
|
||||
for raw in comment.lines() {
|
||||
let line = raw
|
||||
.trim_start_matches(" ")
|
||||
.trim_start_matches("//")
|
||||
.trim_start_matches("///")
|
||||
.trim_start_matches("/**")
|
||||
.trim_start_matches("/*")
|
||||
.trim_start_matches("*/")
|
||||
.trim_start_matches("*")
|
||||
.trim_end();
|
||||
comment_lines.push(line.to_owned());
|
||||
}
|
||||
let text = comment.value();
|
||||
raw_comment += &text;
|
||||
raw_comment += "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut comment_lines = Vec::new();
|
||||
for raw in raw_comment.lines() {
|
||||
let line = raw
|
||||
.trim_start_matches(" ")
|
||||
.trim_start_matches("//")
|
||||
.trim_start_matches("///")
|
||||
.trim_start_matches("/**")
|
||||
.trim_start_matches("/*")
|
||||
.trim_start_matches("*/")
|
||||
.trim_start_matches("*")
|
||||
.trim_end();
|
||||
|
||||
comment_lines.push(line.to_owned());
|
||||
}
|
||||
|
||||
comment_lines
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <new>
|
||||
|
||||
/// Constants shared by multiple CSS Box Alignment properties
|
||||
///
|
||||
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
struct StyleAlignFlags {
|
||||
uint8_t bits;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <new>
|
||||
|
||||
/// Constants shared by multiple CSS Box Alignment properties
|
||||
///
|
||||
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
struct AlignFlags {
|
||||
uint8_t bits;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct StyleAlignFlags {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct StyleAlignFlags {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct AlignFlags {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
typedef struct AlignFlags {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* The root of all evil.
|
||||
*
|
||||
* But at least it contains some more documentation as someone would expect
|
||||
* from a simple test case like this.
|
||||
*
|
||||
* # Hint
|
||||
*
|
||||
* Always ensure that everything is properly documented, even if you feel lazy.
|
||||
* Sometimes** it is also helpful to include some markdown formatting.
|
||||
*/
|
||||
void root(void);
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
/**
|
||||
* The root of all evil.
|
||||
*
|
||||
* But at least it contains some more documentation as someone would expect
|
||||
* from a simple test case like this.
|
||||
*
|
||||
* # Hint
|
||||
*
|
||||
* Always ensure that everything is properly documented, even if you feel lazy.
|
||||
* Sometimes** it is also helpful to include some markdown formatting.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* The root of all evil.
|
||||
*
|
||||
* But at least it contains some more documentation as someone would expect
|
||||
* from a simple test case like this.
|
||||
*
|
||||
* # Hint
|
||||
*
|
||||
* Always ensure that everything is properly documented, even if you feel lazy.
|
||||
* Sometimes** it is also helpful to include some markdown formatting.
|
||||
*/
|
||||
void root(void);
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
/**
|
||||
* The root of all evil.
|
||||
*
|
||||
* But at least it contains some more documentation as someone would expect
|
||||
* from a simple test case like this.
|
||||
*
|
||||
* # Hint
|
||||
*
|
||||
* Always ensure that everything is properly documented, even if you feel lazy.
|
||||
* Sometimes** it is also helpful to include some markdown formatting.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
||||
extern "C" {
|
||||
|
||||
/// The root of all evil.
|
||||
///
|
||||
/// But at least it contains some more documentation as someone would expect
|
||||
/// from a simple test case like this.
|
||||
///
|
||||
/// # Hint
|
||||
///
|
||||
/// Always ensure that everything is properly documented, even if you feel lazy.
|
||||
/// Sometimes** it is also helpful to include some markdown formatting.
|
||||
void root();
|
||||
|
||||
} // extern "C"
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
struct StyleAlignFlags {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
struct StyleAlignFlags {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
struct AlignFlags {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
/**
|
||||
* Constants shared by multiple CSS Box Alignment properties
|
||||
*
|
||||
* These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||
*/
|
||||
struct AlignFlags {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* The root of all evil.
|
||||
*
|
||||
* But at least it contains some more documentation as someone would expect
|
||||
* from a simple test case like this.
|
||||
*
|
||||
* # Hint
|
||||
*
|
||||
* Always ensure that everything is properly documented, even if you feel lazy.
|
||||
* Sometimes** it is also helpful to include some markdown formatting.
|
||||
*/
|
||||
void root(void);
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
/**
|
||||
* The root of all evil.
|
||||
*
|
||||
* But at least it contains some more documentation as someone would expect
|
||||
* from a simple test case like this.
|
||||
*
|
||||
* # Hint
|
||||
*
|
||||
* Always ensure that everything is properly documented, even if you feel lazy.
|
||||
* Sometimes** it is also helpful to include some markdown formatting.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
@@ -0,0 +1,12 @@
|
||||
/// The root of all evil.
|
||||
///
|
||||
/// But at least it contains some more documentation as someone would expect
|
||||
/// from a simple test case like this.
|
||||
///
|
||||
/// # Hint
|
||||
///
|
||||
/// Always ensure that everything is properly documented, even if you feel lazy.
|
||||
/// **Sometimes** it is also helpful to include some markdown formatting.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root() {
|
||||
}
|
||||
Reference in New Issue
Block a user