Add expansion context analyzer for refactoring rules
Refactoring rules need to know the expansion context ('module, 'expression, 'internal-definition) of forms to determine valid transformations. This adds an expansion analyzer that labels each form with its context based on its position in the expanded syntax tree.
Implementation
-
New analyzer:
expansion-context-analyzer.rkttraverses expanded syntax usingsyntax-searchto annotate forms based on structural position- Forms directly under
#%module-begin→'modulecontext - Subforms of
#%plain-app→'expressioncontext - Lambda/let body forms →
'internal-definitioncontext
- Forms directly under
-
Test suite:
expansion-context-analyzer-test.rktvalidates context labeling per the issue spec
Status
Core analyzer structure is in place but patterns aren't matching as expected. The #%module-begin pattern should annotate forms at paths like /3/1, but currently only wrapper-level paths (/1, /2, /3) are being annotated. Likely cause: syntax-search recursion semantics or phase handling in pattern matching.
Test output shows properties are being created but filtered out due to "multiple expanded forms claim to originate from that path" - suggesting the analyzer is annotating expanded paths that map ambiguously to original code positions.
Needs further debugging of pattern matching behavior and the relationship between expanded syntax paths and original syntax paths in the analysis infrastructure.
Original prompt
This section details on the original issue you should resolve
<issue_title>Expansion context analyzer</issue_title> <issue_description>Whenever a form is being expanded, the result of
syntax-local-contexthas one of five values:'expression,'top-level,'module,'module-begin, or a value representing a specific definition context. This is useful information to know when inside refactoring rules, as it can affect what sort of transformations might be possible or reasonable. There should be a custom expansion analyzer that labels the expansion context of all forms in the fully expanded syntax. Here's some test cases:#lang resyntax/test header: - #lang racket/base analysis-test: "code in a module is in a module context" - (+ 1 2 3) @inspect - (+ 1 2 3) @property expansion-context @assert module analysis-test "function arguments are in an expression context" - (+ 1 2 3) @inspect - 2 @property expansion-context @assert expression analysis-test "code in a function body is in an internal definition context" -------------------- (define (f) (+ 1 2 3)) -------------------- @inspect - (+ 1 2 3) @property expansion-context @assert internal-definition ```</issue_description> ## Comments on the Issue (you are @copilot in this section) <comments> </comments>
- Fixes jackfirth/resyntax#685
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.