Skip to content

refactor(actions): emit inherent subtree moves and suppress redundant scaffolding - #119

Merged
HarshK97 merged 2 commits into
mainfrom
fix/ast-action-collapsing
Aug 19, 2026
Merged

refactor(actions): emit inherent subtree moves and suppress redundant scaffolding#119
HarshK97 merged 2 commits into
mainfrom
fix/ast-action-collapsing

Conversation

@HarshK97

@HarshK97 HarshK97 commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Problem

  1. Whenever a node moved in chawathe.go, we were walking all its descendants and creating individual Move actions for every single child and grandchild in that subtree. Then in collapsing.go, we tried to reconstruct whether all those children moved together to collapse them back into a single subtree move. This was fragile and broke anytime a child inside a moved block was deleted or modified, which caused the parent move to get killed and left a bunch of messy orphan moves behind.
  2. Scaffolding containers like statement_list, declaration_list, and block were emitting separate Delete and Move actions even when their parent container was already deleted or moved.
  3. On a single line, outer wrappers like expression_statement were emitting redundant actions alongside inner child expressions (like selector_expression or call_expression) because we were only checking one level up instead of checking the whole single-line parent chain.
  4. In TopDown matching, when multiple identical isomorphic subtrees were candidates (like repeated helper calls or data fields), tie-breakers only checked identifier names and parent Dice score. If neither broke the tie, subtrees could match across completely unrelated sections of the file instead of staying within their local context.

What Changed

  • Dropped addDescendantMoves in chawathe.go so parent Move actions are marked with Subtree: len(children) > 0 directly, instead of spamming individual child moves and trying to stitch them back together later.
  • Removed the bottom-up move collapsing loop in collapsing.go since moves are now inherently subtree-scoped from the generator.
  • Added a second pass (suppressRedundantScaffolding) to drop redundant scaffolding Insert, Delete, and Move actions when their parent container is already doing the work.
  • Updated suppressInlineParentRedundancy to walk up single-line ancestors so wrapper expressions on the same line get pruned cleanly.
  • Cleaned up collapsing.go by removing the unused contentMoveSuppressed map and deduplicating the scaffolding suppression passes.
  • Added parentLineageSimilarity to TopDown matching to score immediate parent and grandparent node type equality as a tie-breaker, keeping identical subtrees matched to their local peers.
  • Updated AncestorNameSimilarity to collect pair keys from ancestor pairs and scaffolding containers, improving contextual matching in structured data (JSON, YAML, and map literals).
  • Added unit tests in collapsing_test.go and utils_test.go covering scaffolding suppression, multi-level inline pruning, and pair key similarity, and updated golden test fixtures across languages.

Visual Comparison:

c_redis_quadratic_search

Before

image

After

image

… scaffolding

- actions: emit Subtree flags directly on parent Move actions and remove redundant descendant walks
- postprocess: drop bottom-up move tree reconstruction loop in Collapse
- postprocess: suppress redundant scaffolding Delete and Move actions under active parent containers
- postprocess: walk single-line ancestor chains in suppressInlineParentRedundancy to prune wrapper expressions
- postprocess: remove dead contentMoveSuppressed map and deduplicate scaffolding suppression passes
- tests: add unit tests for scaffolding suppression and update golden fixtures across test corpus
…atching

When multiple identical isomorphic subtrees are candidates in TopDown matching, break score ties using 2-level parent AST type equality and ancestor pair keys so cohesive calls and data scopes match within context without stealing peers across distant sections.

- engine: add parentLineageSimilarity to scoredPair in TopDown
- engine: collect getKeyLabel from ancestor pairs and scaffolding in AncestorNameSimilarity
- engine: add unit test for pair key ancestor similarity
- tests: update golden fixtures for cohesive call and manifest matching
@HarshK97
HarshK97 force-pushed the fix/ast-action-collapsing branch from f407339 to c74b1bd Compare August 19, 2026 14:40
@HarshK97
HarshK97 merged commit 7d2b258 into main Aug 19, 2026
16 checks passed
@HarshK97
HarshK97 deleted the fix/ast-action-collapsing branch August 19, 2026 15:38
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