Skip to content

Commit

Permalink
Fix doc comments when multi-line annotations are used to avoid commen…
Browse files Browse the repository at this point in the history
…ts containing annotation values
  • Loading branch information
novafacing committed Aug 1, 2023
1 parent 41396a6 commit 3e7fecf
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/bindgen/ir/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,37 @@ pub struct Documentation {

impl Documentation {
pub fn load(attrs: &[syn::Attribute]) -> Self {
let attrs_lines = attrs.get_comment_lines();
let annotation_lines: Vec<usize> = attrs_lines
.iter()
.enumerate()
.filter_map(|(i, line)| {
let line = line.trim_start();
if !line.starts_with("cbindgen:") {
return None;
}

Some(i)
})
.collect();

let mut skip_lines = annotation_lines.clone();

annotation_lines.iter().for_each(|line_index| {
for i in *line_index..attrs_lines.len() - 1 {
if !attrs_lines[i].ends_with('\\') {
break;
}
skip_lines.push(i);
}
});

let doc = attrs
.get_comment_lines()
.into_iter()
.filter(|x| !x.trim_start().starts_with("cbindgen:"))
.enumerate()
.filter(|(i, _)| !skip_lines.contains(i))
.map(|(_, l)| l)
.collect();

Documentation { doc_comment: doc }
Expand Down

0 comments on commit 3e7fecf

Please sign in to comment.