fix: Align execute-dynamic-code diagnostic context with user snippet lines#1722
Conversation
…lines Map #line-reported compiler locations to the extracted user region instead of wrapper boilerplate so Context and Line refer to the same source lines. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Warning Review limit reached
Next review available in: 51 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Map Column/PointerColumn to user-snippet basis by subtracting wrapper indent, build Context from original user code instead of hoisted wrapped lines, hoist TryExtract outside the diagnostic loop, and drop trailing empty context lines so caret placement matches the reported error site. Co-authored-by: Cursor <cursoragent@cursor.com>
Explain why Context uses original user text while compiler columns come from hoisted wrapped source so reviewers know caret may drift slightly. Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Fix execute-dynamic-code compilation diagnostics so
Line,Column,PointerColumn, andContextall use the same user-snippet basis (A-2).Semantic change:
ColumnandPointerColumnare now user-snippet-relative when the wrapped source contains#linemarkers (previously onlyLinewas remapped; columns stayed wrapper-physical).Pre-implementation verification
Repro (real machine, before fix)
Command:
uloop execute-dynamic-code --code $'int a=1;\nint b=2;\nint c=3;\nint d=4;\nint e= ;\nreturn a;'Lineint e= ;)ContextL5using System.Collections.GenericAdditional case (
UndefinedSymbolOnLine3on user line 3):Line=3was correct, butContextL3 showedusing System;.Conclusion:
#linealready mapsLineto user snippet lines;Contextincorrectly indexed into full wrappedUpdatedCode.Auto-injected
usingcount does not changeLine(still user-relative). Literal hoisting rewrites user lines in wrapped output but#linemapping keepsLineon user ordinal.Convention checklist
Context/Hintaccuracy); no protocol bumpImplementation
WrapperTemplate.UserBodyIndentSpaces(12): public constant for wrapper user-line indentDynamicCodeDiagnosticColumnMapper: subtract indent from wrapped column, clamp ≥1DynamicCodeUserSnippetLines: split originalparameters.Code, trim trailing empty linesDynamicCodeExecutionResponseFactory: pass original user snippet for Context; map columns to user basis;TryExtractonce outside diagnostic loopExecuteDynamicCodeUseCase: passparameters.Codeto response factoryKnown limitation: when literals are hoisted on the same line before the error column, caret may drift a few columns because compiler column is measured on hoisted wrapped source while Context shows original text. Documented in code comment.
Verification
dist/darwin-arm64/uloop compile— 0 errors / 0 warningsDynamicCodeDiagnosticContextBuilderTests+DynamicCodeDiagnosticColumnMapperTests+DynamicCodeExecutionResponseFactoryTests— 11 passedDiagnostics[0]):{ "Message": "CS1525: Invalid expression term ';'", "Line": 5, "Column": 8, "ErrorCode": "CS1525", "Hint": "", "Suggestions": [], "Context": "L2:int b=2;\nL3:int c=3;\nL4:int d=4;\nL5:int e= ;\n ^\nL6:return a;\n", "PointerColumn": 8 }Caret
^is at column 8 (under;inint e= ;). Context shows original user lines (no__uloop_literal_N). No trailingL7:empty line.Made with Cursor