fix: handle multi-line function calls in behavior instrumentation#1913
fix: handle multi-line function calls in behavior instrumentation#1913HeshamHM28 merged 2 commits intomainfrom
Conversation
wrap_target_calls_with_treesitter() operated line-by-line but tree-sitter
byte offsets span multiple lines. Multi-line calls like:
func(arg1,
arg2);
only had the first line replaced, leaving orphaned continuation lines
that caused compilation errors (80% of Spring AI functions skipped).
Rewrote to operate on the full body text with pre-computed character
offsets, processing calls back-to-front — same approach as
_add_timing_instrumentation which never had this bug.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @HeshamHM28's task in 5m 3s —— View job PR Review —
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mashraf-222
left a comment
There was a problem hiding this comment.
Validated E2E with multi-line calls in test code (both embedded in assertEquals and standalone expression statements). Behavior instrumentation handles multi-line byte ranges correctly — instrumented code compiles, runs, and produces optimization candidates. 46/46 unit tests pass.
Problem
wrap_target_calls_with_treesitter()ininstrumentation.pyprocesses test method bodies line-by-line, but tree-sitter byte offsets can span multiple lines. When a function call like:gets instrumented, only the first line is replaced. The continuation line becomes an orphaned fragment:
Fix
Rewrote
wrap_target_calls_with_treesitter()to operate on the fullbody_textstring with pre-computed character offsets, processing calls back-to-front — the same approach_add_timing_instrumentationalready uses successfully.Key changes:
Test plan
TestMultiLineCallInstrumentationwith 2 new tests:assertEquals(behavior mode)🤖 Generated with Claude Code