Repository navigation
feat(query): expose structural grammar completion metadata (#1844) - #2025
Conversation
Problem: query completion only projected session field metadata, while the grammar now supports structural exists predicates over messages, actions, and blocks. The parser also had a stale boolean-expression detector that recognized exists message/action but not exists block, so single-child block predicates could miss the Boolean grammar path.\n\nWhat changed: add typed structural query-unit metadata to the expression module, expose structural unit/field completion candidates from that metadata, and route completion contexts after exists or inside exists <unit>(...) through the shared registry. Fix the block detector so compile_expression uses the same grammar path for exists block(...) as parse_expression_ast.\n\nVerification: devtools test tests/unit/cli/test_command_aux_runtime.py tests/unit/cli/test_completion_matrix.py tests/unit/cli/test_query_expression.py -k 'query_structural or block_exists or structural_exists or query_field_completion or query_field_value_completion' -> 17 passed. devtools verify --quick -> exit_code 0. devtools verify reached pytest testmon and was interrupted after ~12m without failure output.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds a ChangesStructural Query Unit Registry and Shell Completion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Expose structural query-unit metadata from the Lark-backed query grammar and use it for shell completion. Completion now suggests
block(afterexistsand structural fields such astype:/text:insideexists block(...), all sourced from the expression module's grammar metadata rather than a parallel list.Problem
The query grammar now supports structural predicates over messages, actions, and blocks, but completion only projected session field metadata from
EXPRESSION_FIELD_REGISTRY. That would make #1844 drift from #2006. There was also a concrete parser-path bug:_is_boolean_expression()recognizedexists message(...)andexists action(...), but notexists block(...), so single-child block predicates could miss the Boolean grammar path.Solution
Added a typed
StructuralQueryUnitInforegistry inpolylogue/archive/query/expression.py, exportedstructural_query_units()/structural_query_fields(), and wiredpolylogue/cli/shell_completion_values.pyto produce structural unit and structural field candidates from that registry. The completion callback now recognizes both full partial text (exists block(t) and normal shell-token contexts (exists+b,exists block(+t). The block detector now routesexists block(...)through the same Boolean grammar as message/action predicates.The durable issue text for #1844 and #2006 was also updated to remove the misleading "floor grammar" framing: there is one Lark grammar/AST/lowerer path.
Verification
nix develop --command devtools test tests/unit/cli/test_command_aux_runtime.py tests/unit/cli/test_completion_matrix.py tests/unit/cli/test_query_expression.py -k 'query_structural or block_exists or structural_exists or query_field_completion or query_field_value_completion'->17 passed, 261 deselectednix develop --command devtools verify --quick->exit_code: 0nix develop --command devtools verifyreachedpytest testmonafter static/generated checks passed and was interrupted after about 12 minutes with no failure output; this PR uses the focused slice plus quick gate as the local evidence.Refs #1844
Refs #2006
Summary by CodeRabbit
New Features
Tests