Skip to content

feat: _parent context for child selector matches#135

Merged
jamestexas merged 2 commits intomainfrom
feat/parent-context
Mar 25, 2026
Merged

feat: _parent context for child selector matches#135
jamestexas merged 2 commits intomainfrom
feat/parent-context

Conversation

@jamestexas
Copy link
Copy Markdown
Contributor

Summary

  • Injects _parent key into child match values when a schema node recurses into children
  • Enables {{._parent.fieldName}} in child templates — chains work: {{._parent._parent.org}}
  • parentAwareMatch wrapper forwards OriginProvider and GetCaptureNode so tree-sitter features (doc comments, location, write-back) continue to work
  • Both processNode (MemoryStore) and collectNodes (SQLite streaming) paths wired

Test plan

  • 3 tests: array fanout, 2-level nesting, no-parent-at-root
  • All existing tests pass (no regressions — OriginProvider + GetCaptureNode forwarding verified)
  • task lint — 0 issues
  • task test — full suite green

Bead: mache-e4a559

🤖 Generated with Claude Code

When a child selector fans out a nested array (e.g. FixedIn[*]),
child templates can now reference parent fields via {{._parent.name}}.
Chains work too: {{._parent._parent.org}}.

parentAwareMatch wraps child matches, forwarding OriginProvider and
GetCaptureNode so tree-sitter features (doc comments, location,
write-back) continue to work.

Both processNode (MemoryStore) and collectNodes (SQLite streaming)
paths are wired.

3 tests, all TDD.

[mache-e4a559]
@jamestexas jamestexas force-pushed the feat/parent-context branch from 5dc0c74 to 92139b4 Compare March 25, 2026 21:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds parent-context propagation to ingestion match values so child node/file templates can reference parent fields via {{._parent.field}} (including multi-level chaining), while preserving tree-sitter-origin features by forwarding relevant interfaces.

Changes:

  • Introduces parentAwareMatch wrapper to inject a _parent map into Match.Values() and forward OriginProvider + GetCaptureNode.
  • Threads parent match values through both ingestion paths: processNode (MemoryStore) and collectNodes (SQLite streaming).
  • Adds tests covering array fanout, 2-level nesting, and root behavior (no _parent at top level).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
internal/ingest/parent_match.go Adds the match wrapper that injects _parent and forwards tree-sitter-related interfaces.
internal/ingest/parent_context_test.go Adds JSON ingestion tests validating _parent access and chaining semantics.
internal/ingest/engine_records.go Updates processNode call site for the new parent-values parameter.
internal/ingest/engine.go Wires _parent injection into processNode and collectNodes, plus updates call sites/signatures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/ingest/parent_match.go
Comment thread internal/ingest/parent_match.go
Comment thread internal/ingest/engine.go
…eaming test

- Document _parent as reserved key (underscore-prefixed = engine metadata)
- Add TestEngine_ParentContext_SQLiteStreamingPath for collectNodes path
- Values() double-call already fixed by caching in prior commit

[mache-e4a559]
@jamestexas jamestexas merged commit dd5d1a8 into main Mar 25, 2026
14 checks passed
@jamestexas jamestexas deleted the feat/parent-context branch March 25, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants