Skip to content

Commit

Permalink
fix formatting multiline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 5, 2023
1 parent d467b70 commit 64c6f21
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions lib/rivet/src/fmt/comments.ri
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,22 @@ extend Formatter {
self.writeln();
}
} else {
lines := comment.text.trim_space().split_into_lines();
start_break := comment.text[0].is_alnum() or comment.text[0].is_space();
end_break := {
trimmed_bytes := comment.text.trim("\t").as_bytes();
trimmed_bytes[trimmed_bytes.len - 1].is_alnum()
} or {
bytes := comment.text.as_bytes();
bytes[bytes.len - 1].is_space()
};
lines := comment.text.split_into_lines();
self.write("/*");
if start_break {
self.writeln();
}
for line in lines {
self.writeln(line.trim_right(" "));
self.empty_line = false;
}
if end_break {
self.empty_line = true;
} else {
_ = self.remove_new_line();
for i, line in lines {
if i == lines.len - 1 {
self.empty_line = true;
if comment.text[comment.text.len - 1] == b'\n' {
self.writeln(line);
} else {
self.write(line);
}
self.write("*/");
} else {
self.empty_line = false;
self.writeln(line.trim_right(" "));
}
}
self.write("*/");
}
if level == .Indent {
self.indent -= 1;
Expand Down

0 comments on commit 64c6f21

Please sign in to comment.