Skip to content

Commit 54e098c

Browse files
committed
progress
1 parent 29b8040 commit 54e098c

File tree

208 files changed

+27090
-950
lines changed

Some content is hidden

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

208 files changed

+27090
-950
lines changed

agentic/pretty_printer.md

Lines changed: 100 additions & 4 deletions
Large diffs are not rendered by default.

agentic/session_log.md

Lines changed: 241 additions & 2 deletions
Large diffs are not rendered by default.

crates/pgls_pretty_print/src/nodes/a_expr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ fn emit_aexpr_op_any(e: &mut EventEmitter, n: &AExpr) {
139139

140140
e.token(TokenKind::ANY_KW);
141141
e.space();
142+
e.token(TokenKind::L_PAREN);
142143

143144
if let Some(ref rexpr) = n.rexpr {
144145
super::emit_node(rexpr, e);
145146
}
147+
148+
e.token(TokenKind::R_PAREN);
146149
}
147150

148151
// expr op ALL (subquery)
@@ -163,10 +166,13 @@ fn emit_aexpr_op_all(e: &mut EventEmitter, n: &AExpr) {
163166

164167
e.token(TokenKind::ALL_KW);
165168
e.space();
169+
e.token(TokenKind::L_PAREN);
166170

167171
if let Some(ref rexpr) = n.rexpr {
168172
super::emit_node(rexpr, e);
169173
}
174+
175+
e.token(TokenKind::R_PAREN);
170176
}
171177

172178
// expr IS DISTINCT FROM expr2

crates/pgls_pretty_print/src/nodes/a_indices.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ pub(super) fn emit_a_indices(e: &mut EventEmitter, n: &AIndices) {
1010

1111
e.token(TokenKind::L_BRACK);
1212

13-
// Lower bound (if slice)
14-
if let Some(ref lidx) = n.lidx {
15-
super::emit_node(lidx, e);
16-
}
13+
if n.is_slice {
14+
if let Some(ref lidx) = n.lidx {
15+
super::emit_node(lidx, e);
16+
}
1717

18-
// If upper bound exists, this is a slice [lower:upper]
19-
if n.uidx.is_some() {
18+
// Colon distinguishes slice syntax from single index lookups.
2019
e.token(TokenKind::IDENT(":".to_string()));
21-
}
2220

23-
// Upper bound
24-
if let Some(ref uidx) = n.uidx {
25-
super::emit_node(uidx, e);
21+
if let Some(ref uidx) = n.uidx {
22+
super::emit_node(uidx, e);
23+
}
24+
} else {
25+
// Non-slice access should render whichever bound PostgreSQL stored.
26+
match (&n.lidx, &n.uidx) {
27+
(Some(lidx), None) => super::emit_node(lidx, e),
28+
(None, Some(uidx)) => super::emit_node(uidx, e),
29+
(Some(lidx), Some(uidx)) => {
30+
debug_assert!(false, "AIndices with both bounds but is_slice = false");
31+
super::emit_node(lidx, e);
32+
super::emit_node(uidx, e);
33+
}
34+
(None, None) => {}
35+
}
2636
}
2737

2838
e.token(TokenKind::R_BRACK);

crates/pgls_pretty_print/src/nodes/a_indirection.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ pub(super) fn emit_a_indirection(e: &mut EventEmitter, n: &AIndirection) {
1111
// Emit the base expression
1212
// Some expressions need parentheses when used with indirection (e.g., ROW(...))
1313
let needs_parens = if let Some(ref arg) = n.arg {
14+
let has_indices = n
15+
.indirection
16+
.iter()
17+
.any(|node| matches!(node.node.as_ref(), Some(pgls_query::NodeEnum::AIndices(_))));
18+
19+
let safe_without_parens = matches!(
20+
arg.node.as_ref(),
21+
Some(
22+
pgls_query::NodeEnum::ColumnRef(_)
23+
| pgls_query::NodeEnum::ParamRef(_)
24+
| pgls_query::NodeEnum::AIndirection(_)
25+
)
26+
);
27+
1428
matches!(arg.node.as_ref(), Some(pgls_query::NodeEnum::RowExpr(_)))
29+
|| (has_indices && !safe_without_parens)
1530
} else {
1631
false
1732
};

crates/pgls_pretty_print/src/nodes/alter_object_schema_stmt.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::TokenKind;
2-
use crate::emitter::{EventEmitter, GroupKind};
2+
use crate::emitter::{EventEmitter, GroupKind, LineType};
3+
4+
use super::node_list::emit_dot_separated_list;
35
use pgls_query::protobuf::{AlterObjectSchemaStmt, ObjectType};
46

57
pub(super) fn emit_alter_object_schema_stmt(e: &mut EventEmitter, n: &AlterObjectSchemaStmt) {
@@ -15,6 +17,8 @@ pub(super) fn emit_alter_object_schema_stmt(e: &mut EventEmitter, n: &AlterObjec
1517
ObjectType::ObjectView => "VIEW",
1618
ObjectType::ObjectMatview => "MATERIALIZED VIEW",
1719
ObjectType::ObjectIndex => "INDEX",
20+
ObjectType::ObjectOpclass => "OPERATOR CLASS",
21+
ObjectType::ObjectOpfamily => "OPERATOR FAMILY",
1822
ObjectType::ObjectForeignTable => "FOREIGN TABLE",
1923
ObjectType::ObjectCollation => "COLLATION",
2024
ObjectType::ObjectConversion => "CONVERSION",
@@ -45,12 +49,17 @@ pub(super) fn emit_alter_object_schema_stmt(e: &mut EventEmitter, n: &AlterObjec
4549
if let Some(ref relation) = n.relation {
4650
super::emit_range_var(e, relation);
4751
} else if let Some(ref object) = n.object {
48-
super::emit_node(object, e);
52+
match n.object_type() {
53+
ObjectType::ObjectOpclass | ObjectType::ObjectOpfamily => {
54+
emit_operator_collection_object(e, object)
55+
}
56+
_ => super::emit_node(object, e),
57+
}
4958
}
5059

5160
// Emit new schema
5261
if !n.newschema.is_empty() {
53-
e.space();
62+
e.line(LineType::SoftOrSpace);
5463
e.token(TokenKind::SET_KW);
5564
e.space();
5665
e.token(TokenKind::IDENT("SCHEMA".to_string()));
@@ -62,3 +71,19 @@ pub(super) fn emit_alter_object_schema_stmt(e: &mut EventEmitter, n: &AlterObjec
6271

6372
e.group_end();
6473
}
74+
75+
fn emit_operator_collection_object(e: &mut EventEmitter, object: &pgls_query::Node) {
76+
if let Some(pgls_query::NodeEnum::List(list)) = &object.node {
77+
if list.items.len() >= 2 {
78+
let (method_node, name_nodes) = list.items.split_first().unwrap();
79+
emit_dot_separated_list(e, name_nodes);
80+
e.space();
81+
e.token(TokenKind::USING_KW);
82+
e.space();
83+
super::emit_node(method_node, e);
84+
return;
85+
}
86+
}
87+
88+
super::emit_node(object, e);
89+
}

0 commit comments

Comments
 (0)