Skip to content

Commit c31293b

Browse files
committed
progress
1 parent 1dc3a46 commit c31293b

File tree

1,400 files changed

+229895
-5763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,400 files changed

+229895
-5763
lines changed

crates/pgls_pretty_print/src/nodes/a_expr.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn emit_aexpr_nullif(e: &mut EventEmitter, n: &AExpr) {
250250
fn emit_aexpr_in(e: &mut EventEmitter, n: &AExpr) {
251251
if let Some(ref lexpr) = n.lexpr {
252252
super::emit_node(lexpr, e);
253-
e.space();
253+
e.line(LineType::SoftOrSpace);
254254
}
255255

256256
let is_not = extract_simple_operator(&n.name)
@@ -272,7 +272,11 @@ fn emit_aexpr_in(e: &mut EventEmitter, n: &AExpr) {
272272
Some(NodeEnum::SubLink(_)) => super::emit_node(rexpr, e),
273273
_ => {
274274
e.token(TokenKind::L_PAREN);
275+
e.indent_start();
276+
e.line(LineType::Soft);
275277
super::emit_node(rexpr, e);
278+
e.indent_end();
279+
e.line(LineType::Soft);
276280
e.token(TokenKind::R_PAREN);
277281
}
278282
}
@@ -378,7 +382,7 @@ fn emit_aexpr_similar(e: &mut EventEmitter, n: &AExpr) {
378382
fn emit_aexpr_between(e: &mut EventEmitter, n: &AExpr) {
379383
if let Some(ref lexpr) = n.lexpr {
380384
super::emit_node(lexpr, e);
381-
e.space();
385+
e.line(LineType::SoftOrSpace);
382386
}
383387

384388
e.token(TokenKind::BETWEEN_KW);
@@ -391,7 +395,7 @@ fn emit_aexpr_between(e: &mut EventEmitter, n: &AExpr) {
391395
super::emit_node(&list.items[0], e);
392396
}
393397
if list.items.len() >= 2 {
394-
e.space();
398+
e.line(LineType::SoftOrSpace);
395399
e.token(TokenKind::AND_KW);
396400
e.space();
397401
super::emit_node(&list.items[1], e);
@@ -406,7 +410,7 @@ fn emit_aexpr_between(e: &mut EventEmitter, n: &AExpr) {
406410
fn emit_aexpr_not_between(e: &mut EventEmitter, n: &AExpr) {
407411
if let Some(ref lexpr) = n.lexpr {
408412
super::emit_node(lexpr, e);
409-
e.space();
413+
e.line(LineType::SoftOrSpace);
410414
}
411415

412416
e.token(TokenKind::NOT_KW);
@@ -421,7 +425,7 @@ fn emit_aexpr_not_between(e: &mut EventEmitter, n: &AExpr) {
421425
super::emit_node(&list.items[0], e);
422426
}
423427
if list.items.len() >= 2 {
424-
e.space();
428+
e.line(LineType::SoftOrSpace);
425429
e.token(TokenKind::AND_KW);
426430
e.space();
427431
super::emit_node(&list.items[1], e);
@@ -436,7 +440,7 @@ fn emit_aexpr_not_between(e: &mut EventEmitter, n: &AExpr) {
436440
fn emit_aexpr_between_sym(e: &mut EventEmitter, n: &AExpr) {
437441
if let Some(ref lexpr) = n.lexpr {
438442
super::emit_node(lexpr, e);
439-
e.space();
443+
e.line(LineType::SoftOrSpace);
440444
}
441445

442446
e.token(TokenKind::BETWEEN_KW);
@@ -451,7 +455,7 @@ fn emit_aexpr_between_sym(e: &mut EventEmitter, n: &AExpr) {
451455
super::emit_node(&list.items[0], e);
452456
}
453457
if list.items.len() >= 2 {
454-
e.space();
458+
e.line(LineType::SoftOrSpace);
455459
e.token(TokenKind::AND_KW);
456460
e.space();
457461
super::emit_node(&list.items[1], e);
@@ -466,7 +470,7 @@ fn emit_aexpr_between_sym(e: &mut EventEmitter, n: &AExpr) {
466470
fn emit_aexpr_not_between_sym(e: &mut EventEmitter, n: &AExpr) {
467471
if let Some(ref lexpr) = n.lexpr {
468472
super::emit_node(lexpr, e);
469-
e.space();
473+
e.line(LineType::SoftOrSpace);
470474
}
471475

472476
e.token(TokenKind::NOT_KW);
@@ -483,7 +487,7 @@ fn emit_aexpr_not_between_sym(e: &mut EventEmitter, n: &AExpr) {
483487
super::emit_node(&list.items[0], e);
484488
}
485489
if list.items.len() >= 2 {
486-
e.space();
490+
e.line(LineType::SoftOrSpace);
487491
e.token(TokenKind::AND_KW);
488492
e.space();
489493
super::emit_node(&list.items[1], e);
@@ -544,9 +548,20 @@ fn operator_needs_space(op: &str) -> bool {
544548

545549
fn operator_prefers_line_break(name: &[Node]) -> bool {
546550
match extract_simple_operator(name) {
551+
// Comparison operators
547552
Some("=") | Some("<>") | Some("!=") | Some("<") | Some(">") | Some("<=") | Some(">=")
548-
| Some("||") | Some("AND") | Some("and") | Some("OR") | Some("or") => true,
549-
_ => false,
553+
// Logical operators
554+
| Some("||") | Some("AND") | Some("and") | Some("OR") | Some("or")
555+
// Arithmetic operators - allow breaking around these for narrow widths
556+
| Some("+") | Some("-") | Some("*") | Some("/") | Some("%") | Some("^")
557+
// Bitwise operators
558+
| Some("&") | Some("|") | Some("#") | Some("~") | Some("<<") | Some(">>")
559+
// Other common operators
560+
| Some("@") | Some("@@") | Some("->") | Some("->>") | Some("#>") | Some("#>>")
561+
| Some("?") | Some("?|") | Some("?&") | Some("@>") | Some("<@") | Some("&&") => true,
562+
// For any other operator, still allow line breaks - they're likely user-defined
563+
// and we want consistent formatting behavior
564+
_ => true,
550565
}
551566
}
552567

crates/pgls_pretty_print/src/nodes/access_priv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::AccessPriv;
44

55
use super::node_list::emit_comma_separated_list;
@@ -18,7 +18,7 @@ pub(super) fn emit_access_priv(e: &mut EventEmitter, n: &AccessPriv) {
1818

1919
// Optional column list for column-level privileges
2020
if !n.cols.is_empty() {
21-
e.space();
21+
e.line(LineType::SoftOrSpace);
2222
e.token(TokenKind::L_PAREN);
2323
emit_comma_separated_list(e, &n.cols, super::emit_node);
2424
e.token(TokenKind::R_PAREN);

crates/pgls_pretty_print/src/nodes/aggref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(super) fn emit_aggref(e: &mut EventEmitter, n: &Aggref) {
3939
e.token(TokenKind::R_PAREN);
4040

4141
if !n.aggorder.is_empty() {
42-
e.space();
42+
e.line(LineType::SoftOrSpace);
4343
e.token(TokenKind::ORDER_KW);
4444
e.space();
4545
e.token(TokenKind::BY_KW);
@@ -48,7 +48,7 @@ pub(super) fn emit_aggref(e: &mut EventEmitter, n: &Aggref) {
4848
}
4949

5050
if let Some(ref filter) = n.aggfilter {
51-
e.space();
51+
e.line(LineType::SoftOrSpace);
5252
e.token(TokenKind::FILTER_KW);
5353
e.space();
5454
e.token(TokenKind::L_PAREN);

crates/pgls_pretty_print/src/nodes/alias.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use pgls_query::protobuf::Alias;
22

33
use crate::TokenKind;
4-
use crate::emitter::{EventEmitter, GroupKind};
4+
use crate::emitter::{EventEmitter, GroupKind, LineType};
55

66
use super::node_list::emit_comma_separated_list;
77

@@ -19,7 +19,7 @@ pub(super) fn emit_alias(e: &mut EventEmitter, n: &Alias) {
1919

2020
// Add column aliases if present
2121
if !n.colnames.is_empty() {
22-
e.space();
22+
e.line(LineType::SoftOrSpace);
2323
e.token(TokenKind::L_PAREN);
2424
emit_comma_separated_list(e, &n.colnames, |node, e| {
2525
// Column names in alias are String nodes

crates/pgls_pretty_print/src/nodes/alter_collation_stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::AlterCollationStmt;
44

55
use super::node_list::emit_dot_separated_list;
@@ -16,7 +16,7 @@ pub(super) fn emit_alter_collation_stmt(e: &mut EventEmitter, n: &AlterCollation
1616
emit_dot_separated_list(e, &n.collname);
1717
}
1818

19-
e.space();
19+
e.line(LineType::SoftOrSpace);
2020
e.token(TokenKind::IDENT("REFRESH".to_string()));
2121
e.space();
2222
e.token(TokenKind::IDENT("VERSION".to_string()));

crates/pgls_pretty_print/src/nodes/alter_database_refresh_coll_stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::AlterDatabaseRefreshCollStmt;
44

55
pub(super) fn emit_alter_database_refresh_coll_stmt(
@@ -17,7 +17,7 @@ pub(super) fn emit_alter_database_refresh_coll_stmt(
1717
e.token(TokenKind::IDENT(n.dbname.clone()));
1818
}
1919

20-
e.space();
20+
e.line(LineType::SoftOrSpace);
2121
e.token(TokenKind::IDENT("REFRESH".to_string()));
2222
e.space();
2323
e.token(TokenKind::IDENT("COLLATION".to_string()));

crates/pgls_pretty_print/src/nodes/alter_database_set_stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::AlterDatabaseSetStmt;
44

55
pub(super) fn emit_alter_database_set_stmt(e: &mut EventEmitter, n: &AlterDatabaseSetStmt) {
@@ -15,7 +15,7 @@ pub(super) fn emit_alter_database_set_stmt(e: &mut EventEmitter, n: &AlterDataba
1515
}
1616

1717
if let Some(ref setstmt) = n.setstmt {
18-
e.space();
18+
e.line(LineType::SoftOrSpace);
1919
super::emit_variable_set_stmt(e, setstmt);
2020
}
2121

crates/pgls_pretty_print/src/nodes/alter_database_stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::AlterDatabaseStmt;
44

55
use super::node_list::emit_comma_separated_list;
@@ -17,7 +17,7 @@ pub(super) fn emit_alter_database_stmt(e: &mut EventEmitter, n: &AlterDatabaseSt
1717
}
1818

1919
if !n.options.is_empty() {
20-
e.space();
20+
e.line(LineType::SoftOrSpace);
2121
emit_comma_separated_list(e, &n.options, super::emit_node);
2222
}
2323

crates/pgls_pretty_print/src/nodes/alter_enum_stmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::AlterEnumStmt;
44

55
use super::node_list::emit_dot_separated_list;
@@ -18,7 +18,7 @@ pub(super) fn emit_alter_enum_stmt(e: &mut EventEmitter, n: &AlterEnumStmt) {
1818
emit_dot_separated_list(e, &n.type_name);
1919
}
2020

21-
e.space();
21+
e.line(LineType::SoftOrSpace);
2222

2323
// Check if this is ADD VALUE or RENAME VALUE
2424
if !n.old_val.is_empty() {
@@ -54,7 +54,7 @@ pub(super) fn emit_alter_enum_stmt(e: &mut EventEmitter, n: &AlterEnumStmt) {
5454

5555
// Optional BEFORE/AFTER clause
5656
if !n.new_val_neighbor.is_empty() {
57-
e.space();
57+
e.line(LineType::SoftOrSpace);
5858
if n.new_val_is_after {
5959
emit_keyword(e, "AFTER");
6060
} else {

crates/pgls_pretty_print/src/nodes/alter_extension_contents_stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
33
use pgls_query::protobuf::{AlterExtensionContentsStmt, ObjectType};
44

55
pub(super) fn emit_alter_extension_contents_stmt(
@@ -17,7 +17,7 @@ pub(super) fn emit_alter_extension_contents_stmt(
1717
e.token(TokenKind::IDENT(n.extname.clone()));
1818
}
1919

20-
e.space();
20+
e.line(LineType::SoftOrSpace);
2121

2222
// action: 1=ADD, -1=DROP
2323
if n.action == 1 {

0 commit comments

Comments
 (0)