Skip to content

feat(engine): add pair value container and key-name affinity matching - #91

Merged
HarshK97 merged 3 commits into
mainfrom
feat/pair-value-matching
Aug 14, 2026
Merged

feat(engine): add pair value container and key-name affinity matching#91
HarshK97 merged 3 commits into
mainfrom
feat/pair-value-matching

Conversation

@HarshK97

@HarshK97 HarshK97 commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Problem

  1. When diffing key-value containers (like JSON objects, Go struct initializers, Python dicts, or Rust struct patterns), value subtrees inside matched pairs could stay unmapped if top-down passes missed them. So updating a value inside a key-value pair produced noisy Delete and Insert actions instead of an in-place Update.
  2. Unmapped pairs with identical key names produced false Delete and Insert actions when surrounding container structures changed, because the engine lacked key-name affinity resolution for unmapped key-value pairs.
  3. The language rules schema had no generic pairs field to declare key-value pair container types across grammars.

What Changed

  • Added a pairs list field to Rules in internal/treesitter/rules.go and configured key-value pair containers across rules files for C, C++, Go, Java, JavaScript, JSON, Lua, PHP, Python, Ruby, Rust, TSX, TypeScript, and Zig.
  • Added matchPairValues in internal/engine/matcher.go right after top-down and declaration matching. So when two key-value pairs are matched, their value children get connected automatically if their node types match and neither value node was mapped yet.
  • Extended matchPairValues with key-name affinity matching so unmapped pairs fall back to matching by key label identity (getKeyLabel) and parent scope context (getParentPairKey).
  • Centralized getKeyLabel in internal/engine/utils.go so key label extraction is shared across matchers.
  • Added unit tests TestMatchPairValues and TestMatchPairKeyNameAffinity in internal/engine/matcher_test.go and updated integration baseline test data fixtures.

Visual Comparison

  • Example : tests/testdata/json_schemastore_hugo_theme_config/

Before

image

After

image

@HarshK97 HarshK97 changed the title feat(engine): add pair value container matching pass and rules configuration feat(engine): add pair value container and key-name affinity matching Aug 14, 2026
@HarshK97
HarshK97 merged commit 7bcb6cd into main Aug 14, 2026
13 checks passed
@HarshK97
HarshK97 deleted the feat/pair-value-matching branch August 14, 2026 10:59
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.

1 participant