fix: correct comment handling for first line
This commit is contained in:
1 parent
150d824561
commit
47f3cc2529
3 files changed
+45
-28
No files matched your search
@@ -92,29 +92,18 @@ impl Buffer {
|
|||||||
let start = child.span().start();
|
let start = child.span().start();
|
||||||
let line_start = start.line;
|
let line_start = start.line;
|
||||||
|
|
||||||
// make sure the comments are actually relevant to this element.
|
if self.current_element_has_comments(child) {
|
||||||
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() {
|
|
||||||
for (id, line) in self.src[..line_start - 1].iter().enumerate().rev() {
|
for (id, line) in self.src[..line_start - 1].iter().enumerate().rev() {
|
||||||
if line.trim().starts_with("//") || line.is_empty() {
|
if line.trim().starts_with("//") || line.is_empty() {
|
||||||
comments.push(id);
|
if id != 0 {
|
||||||
|
comments.push(id);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if comments.len() == 1 && self.src[comments[0]].is_empty() {
|
|
||||||
comments.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut last_was_empty = false;
|
let mut last_was_empty = false;
|
||||||
for comment_line in comments.drain(..).rev() {
|
for comment_line in comments.drain(..).rev() {
|
||||||
let line = &self.src[comment_line];
|
let line = &self.src[comment_line];
|
||||||
|
|||||||
@@ -216,6 +216,22 @@ impl Buffer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn current_element_has_comments(&self, child: &BodyNode) -> bool {
|
||||||
|
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 {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
|
||||||
|
beginning.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
// check if the children are short enough to be on the same line
|
// check if the children are short enough to be on the same line
|
||||||
// We don't have the notion of current line depth - each line tries to be < 80 total
|
// We don't have the notion of current line depth - each line tries to be < 80 total
|
||||||
// returns the total line length if it's short
|
// returns the total line length if it's short
|
||||||
@@ -229,19 +245,7 @@ impl Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for child in children {
|
for child in children {
|
||||||
let start = child.span().start();
|
if self.current_element_has_comments(child) {
|
||||||
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() {
|
|
||||||
'line: for line in self.src[..child.span().start().line - 1].iter().rev() {
|
'line: for line in self.src[..child.span().start().line - 1].iter().rev() {
|
||||||
match (line.trim().starts_with("//"), line.is_empty()) {
|
match (line.trim().starts_with("//"), line.is_empty()) {
|
||||||
(true, _) => return None,
|
(true, _) => return None,
|
||||||
|
|||||||
@@ -14,5 +14,29 @@ rsx! {
|
|||||||
|
|
||||||
// body
|
// body
|
||||||
div { "text" }
|
div { "text" }
|
||||||
|
|
||||||
|
div {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// adadsasd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// adadsasd
|
||||||
|
// adadsasd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// adadsasd
|
||||||
|
// adadsasd
|
||||||
|
// adadsasd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
div {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user