Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add comments to format output #4397

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
.
max-sixty committed May 12, 2024
commit 47f4fb226081276dc1b9c9e642908c2112f4986c
11 changes: 4 additions & 7 deletions prqlc/prqlc/src/codegen/ast.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ pub(crate) fn write_expr(expr: &Expr) -> String {
}

fn write_within<T: WriteSource>(node: &T, parent: &ExprKind, mut opt: WriteOpt) -> Option<String> {
// dbg!(&node, &parent);
let parent_strength = binding_strength(parent);
opt.context_strength = opt.context_strength.max(parent_strength);

@@ -26,7 +25,7 @@ fn write_within<T: WriteSource>(node: &T, parent: &ExprKind, mut opt: WriteOpt)
// these to write comments for. I'm sure there are better ways to do it.
let enable_comments = opt.enable_comments;
opt.enable_comments = false;
let out = dbg!(node.write(opt.clone()));
let out = node.write(opt.clone());
opt.enable_comments = enable_comments;
out
}
@@ -69,9 +68,6 @@ impl WriteSource for Expr {
}

let comments = find_comments_after(span, &opt.tokens);
// if !comments.is_empty() {
// dbg!(&self, &span, &opt.tokens, &comments);
// }

// If the first item is a comment, it's an inline comment, and
// so add two spaces
@@ -86,7 +82,7 @@ impl WriteSource for Expr {
}

for c in comments {
match dbg!(c.kind) {
match c.kind {
// TODO: these are defined here since the debug
// representations aren't quite right (NewLine is `new
// line` as is used in error messages). But we should
@@ -628,7 +624,8 @@ mod test {
"#,
)
.unwrap();
let span = dbg!(tokens.clone())
let span = tokens
.clone()
.0
.iter()
.find(|t| t.kind == TokenKind::Literal(Literal::Integer(5)))