Skip to content

feat(engine): support declaration body recovery and forward-decl resolution - #116

Merged
HarshK97 merged 1 commit into
mainfrom
feat/declaration-body-recovery
Aug 19, 2026
Merged

feat(engine): support declaration body recovery and forward-decl resolution#116
HarshK97 merged 1 commit into
mainfrom
feat/declaration-body-recovery

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. When declarations were matched by name/receiver in matchDeclarations, only the root declaration nodes were mapped. If the inner body had substantial additions, deletions, or structural modifications, top-down and bottom-up passes could fail to map the body blocks directly, leaving them to be treated as complete deletions and re-insertions rather than modified blocks.
  2. In languages supporting forward declarations or variable declarations sharing the same identifier as a subsequent full definition (such as Lua or C/C++), matchDeclarations could pair a small forward declaration against a full definition on the destination side, leaving the actual definition body unmapped.

What Changed

  • Added Blocks node types to language rules schema in internal/treesitter/rules.go and defined block node types across 14 languages (including compound_statement, block, statement_block, and constructor_body).
  • Added TestEveryLanguageBlocksAreValidSymbols in internal/treesitter/rules_test.go to validate all block symbol types against their respective Tree-sitter grammars.
  • Resolved multiple candidate source declarations in matchDeclarations by subtree size delta, so full definitions map to full definitions and forward declarations do not steal destination functions.
  • Implemented matchDeclarationBodies in internal/engine/matcher.go to locate corresponding block nodes within matched declarations, map them directly, and run Recover down their subtrees.
  • Added unit tests covering cross-construct declaration matching with body recovery and forward-declaration resolution in internal/engine/declaration_test.go.
  • Updated baseline test fixtures across Go, Java, Lua, PHP, Python, Rust, and Zig test suites where declaration bodies and their child statements now map cleanly in place.

Visual Comparison

  • php_guzzle_handler_curl_multi

Before

image

After

image

@HarshK97

Copy link
Copy Markdown
Owner Author

Yesterday, Github was down. Now Github actions huh. Nice

@HarshK97
HarshK97 force-pushed the feat/declaration-body-recovery branch 3 times, most recently from 50e505d to b175caa Compare August 18, 2026 14:02
@HarshK97
HarshK97 force-pushed the feat/declaration-body-recovery branch from b175caa to 57d438b Compare August 18, 2026 16:26
@HarshK97
HarshK97 merged commit 3430879 into main Aug 19, 2026
16 checks passed
@HarshK97
HarshK97 deleted the feat/declaration-body-recovery branch August 19, 2026 03:51
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