Skip to content

fix: Align execute-dynamic-code diagnostic context with user snippet lines#1722

Merged
hatayama merged 3 commits into
feat/cli-ux-guidancefrom
feat/cli-ux-dynamic-code-line-offset
Jul 12, 2026
Merged

fix: Align execute-dynamic-code diagnostic context with user snippet lines#1722
hatayama merged 3 commits into
feat/cli-ux-guidancefrom
feat/cli-ux-dynamic-code-line-offset

Conversation

@hatayama

@hatayama hatayama commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

Fix execute-dynamic-code compilation diagnostics so Line, Column, PointerColumn, and Context all use the same user-snippet basis (A-2).

Semantic change: Column and PointerColumn are now user-snippet-relative when the wrapped source contains #line markers (previously only Line was 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;'
Field Before fix Expected
Line 5 User line 5 (int e= ;)
Context L5 using System.Collections.Generic User line 5

Additional case (UndefinedSymbolOnLine3 on user line 3): Line=3 was correct, but Context L3 showed using System;.

Conclusion: #line already maps Line to user snippet lines; Context incorrectly indexed into full wrapped UpdatedCode.

Auto-injected using count does not change Line (still user-relative). Literal hoisting rewrites user lines in wrapped output but #line mapping keeps Line on user ordinal.

Convention checklist

  • No overloads added
  • No new try-catch
  • Additive behavior only (diagnostic Context/Hint accuracy); no protocol bump
  • Pure C# mapper + extractor with TDD tests; test what-comments; English commits/PR

Implementation

  • WrapperTemplate.UserBodyIndentSpaces (12): public constant for wrapper user-line indent
  • DynamicCodeDiagnosticColumnMapper: subtract indent from wrapped column, clamp ≥1
  • DynamicCodeUserSnippetLines: split original parameters.Code, trim trailing empty lines
  • DynamicCodeExecutionResponseFactory: pass original user snippet for Context; map columns to user basis; TryExtract once outside diagnostic loop
  • ExecuteDynamicCodeUseCase: pass parameters.Code to response factory

Known 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 warnings
  • DynamicCodeDiagnosticContextBuilderTests + DynamicCodeDiagnosticColumnMapperTests + DynamicCodeExecutionResponseFactoryTests — 11 passed
  • Post-fix real repro (raw JSON, Diagnostics[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 ; in int e= ;). Context shows original user lines (no __uloop_literal_N). No trailing L7: empty line.

Made with Cursor

Review in cubic

…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>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@hatayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2738934e-864f-4a65-a880-8981d666c255

📥 Commits

Reviewing files that changed from the base of the PR and between ba0c3b5 and 83547a8.

⛔ Files ignored due to path filters (6)
  • Assets/Tests/Editor/DynamicCodeToolTests/DynamicCodeDiagnosticColumnMapperTests.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/DynamicCodeToolTests/DynamicCodeDiagnosticContextBuilderTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/DynamicCodeDiagnosticColumnMapper.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/DynamicCodeDiagnosticContextBuilder.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/DynamicCodeUserSnippetLines.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/WrappedDynamicCodeUserSnippetExtractor.cs.meta is excluded by none and included by none
📒 Files selected for processing (11)
  • Assets/Tests/Editor/DynamicCodeToolTests/DynamicCodeDiagnosticColumnMapperTests.cs
  • Assets/Tests/Editor/DynamicCodeToolTests/DynamicCodeDiagnosticContextBuilderTests.cs
  • Assets/Tests/Editor/DynamicCodeToolTests/DynamicCodeExecutionResponseFactoryTests.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCodeExecutionResponseFactory.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/DynamicCodeDiagnosticColumnMapper.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/DynamicCodeDiagnosticContextBuilder.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/DynamicCodeUserSnippetLines.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/PreUsingResolver.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/WrappedDynamicCodeUserSnippetExtractor.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/WrapperTemplate.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/ExecuteDynamicCodeUseCase.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cli-ux-dynamic-code-line-offset

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

hatayama and others added 2 commits July 12, 2026 15:54
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>
@hatayama hatayama merged commit ad42b99 into feat/cli-ux-guidance Jul 12, 2026
2 checks passed
@hatayama hatayama deleted the feat/cli-ux-dynamic-code-line-offset branch July 12, 2026 06:57
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