wip: add whitespace parsing to rsx

This commit is contained in:
Jonathan Kelley committed 2022-09-30 10:51:53 -07:00
1 parent 5313fc0cc6
commit 181a51a63b
14 files changed
+278 -24

No files matched your search

+3 -3
View File
@@ -67,8 +67,8 @@ impl Buffer {
match node {
BodyNode::Element(el) => self.write_element(el),
BodyNode::Component(component) => self.write_component(component),
BodyNode::Text(text) => self.write_text(text),
BodyNode::RawExpr(exp) => self.write_raw_expr(exp),
BodyNode::Text(text) => self.write_text(&text.text),
BodyNode::RawExpr(exp) => self.write_raw_expr(&exp.expr),
}
}
@@ -129,7 +129,7 @@ impl Buffer {
for (idx, child) in children.iter().enumerate() {
match child {
// check if the expr is a short
BodyNode::RawExpr(_) => {
BodyNode::RawExpr { .. } => {
self.tabbed_line()?;
self.write_ident(child)?;
if idx != last_child - 1 {
+8 -6
View File
@@ -276,7 +276,7 @@ impl Buffer {
}
match children {
[BodyNode::Text(ref text)] => Some(text.value().len()),
[BodyNode::Text(ref text)] => Some(text.text.value().len()),
[BodyNode::Component(ref comp)] => {
let attr_len = self.field_len(&comp.fields, &comp.manual_props);
@@ -290,7 +290,7 @@ impl Buffer {
}
[BodyNode::RawExpr(ref expr)] => {
// TODO: let rawexprs to be inlined
get_expr_length(expr)
get_expr_length(&expr.expr)
}
[BodyNode::Element(ref el)] => {
let attr_len = self.is_short_attrs(&el.attributes);
@@ -301,8 +301,10 @@ impl Buffer {
if el.children.len() == 1 {
if let BodyNode::Text(ref text) = el.children[0] {
if text.value().len() + el.name.to_string().len() + attr_len < 80 {
return Some(text.value().len() + el.name.to_string().len() + attr_len);
if text.text.value().len() + el.name.to_string().len() + attr_len < 80 {
return Some(
text.text.value().len() + el.name.to_string().len() + attr_len,
);
}
}
}
@@ -316,8 +318,8 @@ impl Buffer {
for item in items {
match item {
BodyNode::Component(_) | BodyNode::Element(_) => return None,
BodyNode::Text(text) => total_count += text.value().len(),
BodyNode::RawExpr(expr) => match get_expr_length(expr) {
BodyNode::Text(text) => total_count += text.text.value().len(),
BodyNode::RawExpr(expr) => match get_expr_length(&expr.expr) {
Some(len) => total_count += len,
None => return None,
},
+18 -1
View File
@@ -18,6 +18,24 @@ impl Buffer {
let end = placement.end();
// let num_spaces_desired = (self.indent * 4) as isize;
// print comments
// let mut queued_comments = vec![];
// let mut offset = 2;
// loop {
// let line = &self.src[start.line - offset];
// if line.trim_start().starts_with("//") {
// queued_comments.push(line);
// } else {
// break;
// }
// offset += 1;
// }
// let had_comments = !queued_comments.is_empty();
// for comment in queued_comments.into_iter().rev() {
// writeln!(self.buf, "{}", comment)?;
// }
// if the expr is on one line, just write it directly
if start.line == end.line {
write!(
@@ -30,7 +48,6 @@ impl Buffer {
// If the expr is multiline, we want to collect all of its lines together and write them out properly
// This involves unshifting the first line if it's aligned
let first_line = &self.src[start.line - 1];
write!(
self.buf,