fix: correct comment handling for first line

This commit is contained in:
Jonathan Kelley committed 2022-07-05 00:30:09 -04:00
1 parent 150d824561
commit 47f3cc2529
3 files changed
+45 -28

No files matched your search

+4 -15
View File
@@ -92,29 +92,18 @@ impl Buffer {
let start = child.span().start();
let line_start = start.line;
// make sure the comments are actually relevant to this element.
let this_line = self.src[line_start - 1].as_str();
let beginning = if this_line.len() > start.column {
this_line[..start.column].trim()
} else {
""
};
if beginning.is_empty() {
if self.current_element_has_comments(child) {
for (id, line) in self.src[..line_start - 1].iter().enumerate().rev() {
if line.trim().starts_with("//") || line.is_empty() {
comments.push(id);
if id != 0 {
comments.push(id);
}
} else {
break;
}
}
}
if comments.len() == 1 && self.src[comments[0]].is_empty() {
comments.pop();
}
let mut last_was_empty = false;
for comment_line in comments.drain(..).rev() {
let line = &self.src[comment_line];