Preserve indentation on comments.
As indentation is a very handy way to structure comments and increase their readability as much of it as possible should be preserved. This removes any trimming of leading white spaces and ensures that any cbindgen annotations are still recognized afterwards. ... fixes #184
This commit is contained in:
committed by
Emilio Cobos Álvarez
parent
47e831753b
commit
1450e39d8f
@@ -50,10 +50,17 @@ impl AnnotationSet {
|
||||
}
|
||||
|
||||
pub fn load(attrs: &[syn::Attribute]) -> Result<AnnotationSet, String> {
|
||||
let lines: Vec<String> = attrs
|
||||
.get_comment_lines()
|
||||
.into_iter()
|
||||
.filter(|x| !x.is_empty() && x.starts_with("cbindgen:"))
|
||||
let lines = attrs.get_comment_lines();
|
||||
let lines: Vec<&str> = lines
|
||||
.iter()
|
||||
.filter_map(|line| {
|
||||
let line = line.trim_start();
|
||||
if !line.starts_with("cbindgen:") {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(line)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let must_use = attrs.has_attr_word("must_use");
|
||||
@@ -62,12 +69,9 @@ impl AnnotationSet {
|
||||
|
||||
// Look at each line for an annotation
|
||||
for line in lines {
|
||||
// Skip lines that don't start with cbindgen
|
||||
if !line.starts_with("cbindgen:") {
|
||||
continue;
|
||||
}
|
||||
debug_assert!(line.starts_with("cbindgen:"));
|
||||
|
||||
// Remove the "cbingen:" prefix
|
||||
// Remove the "cbindgen:" prefix
|
||||
let annotation = &line[9..];
|
||||
|
||||
// Split the annotation in two
|
||||
|
||||
@@ -20,7 +20,7 @@ impl Documentation {
|
||||
let doc = attrs
|
||||
.get_comment_lines()
|
||||
.into_iter()
|
||||
.filter(|x| !x.starts_with("cbindgen:"))
|
||||
.filter(|x| !x.trim_start().starts_with("cbindgen:"))
|
||||
.collect();
|
||||
|
||||
Documentation { doc_comment: doc }
|
||||
@@ -72,9 +72,6 @@ impl Source for Documentation {
|
||||
DocumentationStyle::Auto => unreachable!(), // Auto case should always be covered
|
||||
}
|
||||
|
||||
if line.len() != 0 {
|
||||
out.write(" ");
|
||||
}
|
||||
write!(out, "{}", line);
|
||||
out.new_line();
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ impl SynAttributeHelpers for [syn::Attribute] {
|
||||
{
|
||||
let name = ident.to_string();
|
||||
if &*name == "doc" {
|
||||
let text = content.value().trim().to_owned();
|
||||
let text = content.value().trim_end().to_owned();
|
||||
comment.push(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
*
|
||||
* ////////////////////////////////////////////////////////////////////////////
|
||||
*
|
||||
* # Attention
|
||||
* Attention:
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
@@ -20,11 +20,12 @@ extern "C" {
|
||||
*
|
||||
* ////////////////////////////////////////////////////////////////////////////
|
||||
*
|
||||
* # Attention
|
||||
* Attention:
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
*
|
||||
* ////////////////////////////////////////////////////////////////////////////
|
||||
*
|
||||
* # Attention
|
||||
* Attention:
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
@@ -20,11 +20,12 @@ extern "C" {
|
||||
*
|
||||
* ////////////////////////////////////////////////////////////////////////////
|
||||
*
|
||||
* # Attention
|
||||
* Attention:
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
|
||||
@@ -17,11 +17,12 @@ extern "C" {
|
||||
///
|
||||
/// ////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// # Attention
|
||||
/// Attention:
|
||||
///
|
||||
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
/// marker you need to add at least a single whitespace inbetween the tripple
|
||||
/// slash doc-comment marker and the rest.
|
||||
///
|
||||
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
/// marker you need to add at least a single whitespace inbetween the tripple
|
||||
/// slash doc-comment marker and the rest.
|
||||
void root();
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
*
|
||||
* ////////////////////////////////////////////////////////////////////////////
|
||||
*
|
||||
* # Attention
|
||||
* Attention:
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
@@ -20,11 +20,12 @@ extern "C" {
|
||||
*
|
||||
* ////////////////////////////////////////////////////////////////////////////
|
||||
*
|
||||
* # Attention
|
||||
* Attention:
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*
|
||||
* Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
* marker you need to add at least a single whitespace inbetween the tripple
|
||||
* slash doc-comment marker and the rest.
|
||||
*/
|
||||
void root(void);
|
||||
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
///
|
||||
/// ////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// # Attention
|
||||
/// Attention:
|
||||
///
|
||||
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
/// marker you need to add at least a single whitespace inbetween the tripple
|
||||
/// slash doc-comment marker and the rest.
|
||||
///
|
||||
/// Rust is going to trim all leading `/` symbols. If you want to use them as a
|
||||
/// marker you need to add at least a single whitespace inbetween the tripple
|
||||
/// slash doc-comment marker and the rest.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user