Skip to content

feat(codegen): expose structured generation diagnostics - #294

Merged
tinovyatkin merged 2 commits into
mainfrom
codex/issue-293-builder-diagnostics
Aug 4, 2026
Merged

feat(codegen): expose structured generation diagnostics#294
tinovyatkin merged 2 commits into
mainfrom
codex/issue-293-builder-diagnostics

Conversation

@tinovyatkin

@tinovyatkin tinovyatkin commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • expose successful grammar compiler warnings through Generation::diagnostics()
  • preserve each source-backed Diagnostic primary subject as an exact half-open UTF-8 byte span
  • keep source-less diagnostics unlocated instead of fabricating a span from a fallback SourceId
  • keep antlr4-rust-gen stderr and Generation::warnings() unchanged
  • document and test code-based G4S078 rule-name recovery through Builder

Why

Library consumers could previously inspect structured diagnostics only when generation failed. Successful analysis warnings were reduced to CLI display strings, forcing callers to parse prose to recover subjects such as unreachable parser rule names.

The successful and failed paths now share the same public diagnostic shape, so callers can filter by code and slice the reported source path at byte_span(). Internal diagnostics also record whether their primary span came from source text: source-less loader and invariant errors return None for structured coordinates even when their synthetic fallback SourceId happens to resolve.

Closes #293

Compatibility

This changes only the antlr-rust-codegen library API. Generated Rust and the runtime interface are unchanged, so the generated-code API revision remains unchanged.

Validation

  • cargo fmt --all -- --check
  • cargo test --locked --workspace --all-features
  • cargo clippy --locked --workspace --all-targets --all-features -- -D warnings

Summary by CodeRabbit

  • New Features

    • Generation results now expose structured compiler and generator diagnostics.
    • Diagnostics include severity, source location, diagnostic codes, and precise UTF-8 byte spans.
    • Warnings remain available as rendered command-line messages.
  • Documentation

    • Updated build-time generation documentation to clarify the distinction between inputs, outputs, structured diagnostics, and warnings.

Retain non-fatal grammar compiler diagnostics on Generation instead of exposing them only as rendered warning strings. Preserve each diagnostic's exact primary UTF-8 byte span so library consumers can select by code and recover the source subject without parsing human-readable messages.

Keep antlr4-rust-gen stderr and Generation::warnings() unchanged, document the new API, and cover G4S078 rule-name recovery through Builder.

Fixes #293
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Copy/Paste Detection

No duplications found in 9 changed non-generated Rust file(s) (threshold: 100 tokens).

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Successful generation now exposes structured compiler diagnostics with codes, severities, paths, positions, and UTF-8 byte spans. Existing rendered warning messages remain available. Tests validate empty diagnostics and unreachable-rule diagnostics.

Changes

Structured generation diagnostics

Layer / File(s) Summary
Diagnostic and Generation API
crates/antlr-rust-codegen/src/error.rs, crates/antlr-rust-codegen/src/artifact.rs
Diagnostic stores an optional byte span. Generation stores diagnostics and exposes them through diagnostics().
Compiler diagnostic propagation
crates/antlr-rust-codegen/src/driver.rs
The driver collects structured diagnostics, preserves source spans, renders warning messages, and passes both forms through generation paths.
API documentation and validation
README.md, crates/antlr-rust-codegen/README.md, crates/antlr-rust-codegen/tests/antlr4_rust_gen_cli/multi_recognizer.rs
Documentation describes structured diagnostics and rendered warnings. Tests cover empty diagnostics and structured G4S078 diagnostics with exact source spans.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Builder
  participant Compiler
  participant Generation
  Builder->>Compiler: generate grammar
  Compiler-->>Builder: diagnostics with source spans
  Builder->>Generation: store diagnostics and rendered warnings
  Generation-->>Builder: expose diagnostics()
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The implementation and tests address structured diagnostics, exact spans, G4S078 recovery, and preserved CLI warnings; the related snapshot is excluded from review. Review the excluded snapshot file to verify the complete structured-diagnostic test evidence.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The documentation, API, implementation, and tests are directly related to the linked issue objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: exposing structured diagnostics from successful code generation.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-293-builder-diagnostics

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/antlr-rust-codegen/tests/antlr4_rust_gen_cli/multi_recognizer.rs`:
- Around line 169-172: Add the missing external Insta snapshot for the
builder_structured_non_fatal_diagnostics_with_exact_spans assertion in the
multi-recognizer tests, using the generated output and the expected
multi_recognizer__builder_structured_non_fatal_diagnostics_with_exact_spans.snap
filename.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2d28c9b3-f9ba-4a92-ac1a-34c25300ed31

📥 Commits

Reviewing files that changed from the base of the PR and between 60a7be7 and 12c1974.

⛔ Files ignored due to path filters (1)
  • crates/antlr-rust-codegen/tests/antlr4_rust_gen_cli/snapshots/antlr4_rust_gen_cli__multi_recognizer__builder_structured_non_fatal_diagnostics_with_exact_spans.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • README.md
  • crates/antlr-rust-codegen/README.md
  • crates/antlr-rust-codegen/src/artifact.rs
  • crates/antlr-rust-codegen/src/driver.rs
  • crates/antlr-rust-codegen/src/error.rs
  • crates/antlr-rust-codegen/tests/antlr4_rust_gen_cli/multi_recognizer.rs

@claude

claude Bot commented Aug 4, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12c1974fad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/antlr-rust-codegen/src/driver.rs Outdated
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

📊 Source Code Metrics (this PR vs main)

File Cyclomatic Cognitive Functions LLOC MI
crates/antlr-rust-codegen/src/grammar/semantics.rs 341 (main: 343) 🟢 314 ⚪ 73 ⚪ 553 ⚪ 0 ⚪
crates/antlr-rust-codegen/src/grammar/compiler.rs 62 (main: 63) 🟢 22 ⚪ 19 ⚪ 86 ⚪ 5.34 (main: 5.10) 🟢
crates/antlr-rust-codegen/src/error.rs 30 (main: 29) 🔴 6 ⚪ 17 (main: 16) 🔴 25 (main: 24) 🔴 21.39 (main: 22.40) 🔴
crates/antlr-rust-codegen/src/grammar/diagnostic.rs 21 (main: 16) 🔴 4 (main: 3) 🔴 11 (main: 8) 🔴 22 (main: 19) 🔴 22.96 (main: 26.30) 🔴
crates/antlr-rust-codegen/src/artifact.rs 33 (main: 32) 🔴 18 ⚪ 10 (main: 9) 🔴 35 (main: 34) 🔴 23.31 (main: 24.35) 🔴
crates/antlr-rust-codegen/src/driver.rs 74 (main: 69) 🔴 52 ⚪ 7 (main: 5) 🔴 107 (main: 98) 🔴 6.68 (main: 8.91) 🔴
crates/antlr-rust-codegen/src/grammar/validation.rs 44 (main: 45) 🟢 50 ⚪ 3 ⚪ 41 ⚪ 21.08 (main: 20.67) 🟢

Generated by mehen v1.8.0 — the code quality watcher.

Track whether compiler diagnostic primary spans came from source text instead of inferring provenance from a resolvable SourceId. Source-less loader and invariant errors keep their existing display fallback but no longer expose fabricated line, column, or byte ranges through Builder.

Cover a valid first root followed by a missing second root while retaining exact G4S078 spans for authored diagnostics.
@tinovyatkin
tinovyatkin merged commit ef1bdd0 into main Aug 4, 2026
13 of 14 checks passed
@tinovyatkin
tinovyatkin deleted the codex/issue-293-builder-diagnostics branch August 4, 2026 12:06
@ophiarch ophiarch Bot mentioned this pull request Aug 4, 2026
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.

codegen: expose structured non-fatal diagnostics from Builder

1 participant