Skip to content

cli: rustc-style diagnostics with a source excerpt and carets (#277 part 2) - #303

Merged
GoKubar merged 2 commits into
mainfrom
agent/daniel-parent/cli-rich-diagnostics
Sep 14, 2026
Merged

GoKubar merged 2 commits into
mainfrom
agent/daniel-parent/cli-rich-diagnostics

Conversation

@d-q222

@d-q222 d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Part (2) of #277: the flashtex CLI renderer. Lane daniel-parent (Claude Max 20x, mac-m5pro-dq222), claim GH-277-cli, approved by the Commander on #2 at 04:23Z. This is not daniel-vpclaude's lane.

What changes

  • --diagnostics=full|short|json. full is the new rustc-style form. short is the one-line line_text, byte-for-byte unchanged. json is an alias for --json.
  • Default: full when stderr is a terminal, short when piped. CI, scripts and every existing tests/cli.rs assertion see identical output. Checked on HW1: piped default output equals --diagnostics=short.
  • --color=auto|always|never. auto means colour on a terminal unless NO_COLOR is set.
  • Existing fields only: code, message, path/line/column, byte span and recovery. There is no dependency on diagnostics: rustc-style reports in the CLI and the app — source excerpt, carets, labels, suggested fix #277 part (1). When labels/help land, the renderer gains = help: lines without changing this path.

Output (HW1 and a small demo, --diagnostics=full)

warning[compiler]: packages amsmath, amssymb are recognised but not implemented
 --> HW1.tex:6:1
  |
6 | \usepackage{amsmath,amssymb,amsthm}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = recovery: continued without package-specific commands or formatting

warning[compiler]: packages microtype are recognised but not implemented
 --> HW1.tex:8:1
  |
8 | \usepackage{microtype}
  | ^^^^^^^^^^^^^^^^^^^^^^
  |
  = recovery: continued without package-specific commands or formatting

error[missing_file]: \input{missing}: no file found (tried missing.tex, missing)
 --> demo.tex:4:1
  |
4 | \input{missing}
  | ^^^^^^^^^^^^^^^

error[compiler]: included file not found: looked for 'missing' and 'missing.tex'
 --> demo.tex:4:1
  |
4 | \input{missing}
  | ^^^^^^
  |
  = recovery: skipped the missing include and continued

error[compiler]: \undefinedmacro is not supported by this compiler version; unrestricted TeX math mode is not implemented
 --> demo.tex:3:31
  |
3 | The filter $\tilde{c}_t$ uses \undefinedmacro{x} here.
  |                               ^^^^^^^^^^^^^^^
  |
  = recovery: skipped the command; any braced argument was typeset as plain text

warning[math_resource_profile]: lmmi10: glyphs drawn from latinmodern-math (one 10pt design); no optical-size OpenType outline resource exists for this family, so the outlines are not the reference's lmmi10 design

Tests

  • cargo test in crates/flashtex-cli: 13/13 unit tests (7 new renderer tests: gutter and carets, no position, tabs and multi-byte with an empty span, elided long spans, a span past EOF, recovery wrapping at 80 columns, colour on/off).
  • Integration: 12/13, including the new diagnostics_full_shows_the_source_line_and_carets.
  • Pre-existing failure, not from this PR: multi_file_project_resolves_inputs_from_the_project_root (tests/cli.rs:142, no diagnostic under sections/) fails the same way on unmodified main 9bd4b025.

Not in this PR

Parts (1) structured fields, (3) message rewrites and (4) the Mac Problems panel remain open on #277.

…art 2)

`flashtex check`/`build`/`watch` print each diagnostic as a header, a
`--> file:line:col` pointer, the source line(s) under a line-number
gutter, carets under the byte span and a wrapped `= recovery:` line.

- `--diagnostics=full|short|json`: full is the new form; short is the
  unchanged one-line `line_text`; json is `--json`. The default is full
  when stderr is a terminal and short otherwise, so piped output and
  scripts see exactly what they did before.
- `--color=auto|always|never`; auto is on for a terminal unless NO_COLOR.
- Uses only the fields a diagnostic already has (code, message, span,
  recovery). Structured labels/help from #277 part (1) can be added to
  the renderer without changing this path.
- Spans: tabs expanded so carets line up, multi-byte text, empty spans
  and spans past the end of the text get one caret, spans longer than
  four lines show the first two and the last.

Tests: 7 renderer unit tests, one end-to-end test for the flags. The
pre-existing multi_file_project_resolves_inputs_from_the_project_root
failure reproduces on unmodified main 9bd4b02 and is not touched here.

Implementation-Agent: daniel-parent (mac-m5pro-dq222)
Commit-Executor: git, direct
Co-authored-by: d-q222 <[email protected]>
@GoKubar
GoKubar merged commit 0ec3812 into main Sep 14, 2026
20 checks passed
@GoKubar
GoKubar deleted the agent/daniel-parent/cli-rich-diagnostics branch September 14, 2026 14:43
d-q222 added a commit that referenced this pull request Sep 14, 2026
main.rs/report.rs add/add conflicts: main's copies are byte-identical to #303's
final head (78b8a8d); this branch is #303 plus the fold-repeats and watch-clear
changes, so kept this branch's side.

Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
GoKubar pushed a commit that referenced this pull request Sep 14, 2026
… (re-opened #310 onto main after #303 merged) (#387)

* cli: rustc-style diagnostics with a source excerpt and carets (#277 part 2)

`flashtex check`/`build`/`watch` print each diagnostic as a header, a
`--> file:line:col` pointer, the source line(s) under a line-number
gutter, carets under the byte span and a wrapped `= recovery:` line.

- `--diagnostics=full|short|json`: full is the new form; short is the
  unchanged one-line `line_text`; json is `--json`. The default is full
  when stderr is a terminal and short otherwise, so piped output and
  scripts see exactly what they did before.
- `--color=auto|always|never`; auto is on for a terminal unless NO_COLOR.
- Uses only the fields a diagnostic already has (code, message, span,
  recovery). Structured labels/help from #277 part (1) can be added to
  the renderer without changing this path.
- Spans: tabs expanded so carets line up, multi-byte text, empty spans
  and spans past the end of the text get one caret, spans longer than
  four lines show the first two and the last.

Tests: 7 renderer unit tests, one end-to-end test for the flags. The
pre-existing multi_file_project_resolves_inputs_from_the_project_root
failure reproduces on unmodified main 9bd4b02 and is not touched here.

Implementation-Agent: daniel-parent (mac-m5pro-dq222)
Commit-Executor: git, direct
Co-authored-by: d-q222 <[email protected]>

* cli: fold per-font warnings into one entry, clear the terminal between watch rebuilds

`--diagnostics=full` printed one entry per math font for the same
`math_resource_profile` warning (4 of HW1's 6 diagnostics). Positionless
diagnostics that differ only in a leading `name:`, wherever else the message
repeats that name, now print as one entry listing every name:

  warning[math_resource_profile]: lmex10, lmmi10, lmmi8, lmsy10: glyphs drawn from latinmodern-math ...

The summary counts, `--diagnostics=short`, piped output and `--json` are
unchanged; nothing is hidden or reclassified. `watch` clears a terminal
before each rebuild so the latest run is the only one on screen (piped
stderr is untouched).

Tests: 2 new unit tests (fold in place with the name repeated in the
message; located, single and multi-word-name diagnostics never rewritten).
flashtex-cli: 15 unit, 12/13 integration; the one failure is the fixture
drift fixed separately in #308.

Implementation-Agent: daniel-parent (mac-m5pro-dq222)
Commit-Executor: git, direct
Co-authored-by: d-q222 <[email protected]>
GoKubar added a commit that referenced this pull request Sep 14, 2026
…th a replacement edit (#277 parts 1+3) (rebase of #346) (#389)

* compiler: \maketitle without \author warns like LaTeX; unsupported text commands stop blaming math mode

GH#244, both parts.

A. latex.ltx defines `\def\@author{\@latex@warning@no@line{No \noexpand\author
given}}`, so a missing \author is a warning and the title block is still set.
This compiler refused to produce any block and raised an error instead.
- A missing \author now gives the warning "No \author given" and the title
  block, with no author line.
- `\author{}`, or only blank \and slots, is an author that is given but
  empty. pdfLaTeX sets it silently, so there is no diagnostic.
The issue asked for a warning in the \author{} case; the pdflatex oracle
says there is none.

pdflatex 1.40.29 oracle, `\the\pagetotal` after \maketitle:
  \author{A}  116.86673pt, no warning
  \author{}   115.33337pt, no warning
  no \author  116.86673pt, "LaTeX Warning: No \author given."
The v1 layout still advances the author line in both empty cases. The 1.53 pt
that pdfLaTeX gives back for \author{} is recorded, not modelled.

B. Parser::unsupported is the text-mode fallback, but every message it
emitted ended with "; unrestricted TeX math mode is not implemented". The
message is now "\X is not supported by this compiler version".
tests/acceptance.rs' "math ... reported" assertion was satisfied only by that
misleading suffix on \tikz ($x^2$ has been implemented for a long time); it now
asserts that nothing mentions math mode.

Regenerated with their own ignored generators: RECOVERY.md and
UNSUPPORTED.md. UNSUPPORTED.md also picks up an \includegraphics message that
had changed earlier without a regen.

Product path (parser.rs applied to render-pipeline/vendor/compiler locally,
then reverted): fixtures/real-world/math-sheet goes from 1 error to 0 errors,
7 warnings, 2 pages (the reference has 2). HW1 stays at 3 pages / 0 errors / 7
warnings and HW2 at 3 / 0 / 8.

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ

* compiler: rustfmt the new maketitle tests

Implementation-Agent: daniel-vpclaude (Claude Code, Claude Pro plan)
Commit-Executor: daniel-vpclaude, direct git (Cursor-limit fallback)
Co-authored-by: d-q222 <[email protected]>

Claude-Session: https://claude.ai/code/session_012iWhnaQddU1UTMh6ZssGBJ

* wip(#277): additive runtime-v1 proposal for diagnostic labels/notes/help

Add protocol/proposals/runtime-v1-structured-diagnostics.md only. Optional
labels (runtime-v1 source spans + text + primary), notes[], and help
{message, replacement?: {start_byte,end_byte,text}} on each diagnostic.
message stays one line without recovery; omitted fields keep JSON
byte-identical. Frozen contracts and schema are untouched.

Ran: none (docs-only checkpoint). Next: merge origin/agent/daniel-vpclaude/maketitle-no-author if it still touches Parser::unsupported, then Diagnostic fields, then the first ~20 helps.

Open questions: render-pipeline from_compiler does not forward these fields (or code); CLI #303 and the Mac pipeline path need a later re-pin, out of this lane.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): optional Diagnostic labels/notes/help, JSON omit-when-empty

Compiler Diagnostic gains labels, notes, and help (empty by default).
JSON emits them only when set; unset diagnostics stay byte-identical.
Incremental mapping shifts label and replacement spans. Merged #305 first
so Parser::unsupported text is the post-maketitle wording.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- cargo test --manifest-path crates/compiler/Cargo.toml --lib: test result: ok. 300 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test diagnostic_codes: test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test recovery: test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
- --test supported_latex: test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: rewrite the first ~20 highest-frequency messages with a real help.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): real help on the highest-frequency compiler diagnostics

Attach optional help (and a primary label where it captions the span)
without changing message text. Unsupported commands name package or math
mode; packages/environments say what to do; missing $ / } / ] and script
markers / \frac get wrap-or-close advice; undefined \ref offers the nearest
\label by edit distance; missing includes name the paths tried. Built on
the #305 Parser::unsupported wording. No recovery.rs message strings
changed.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- cargo test --manifest-path crates/compiler/Cargo.toml --lib: test result: ok. 300 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test diagnostic_codes: test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test recovery: test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
- --test supported_latex: test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- --test maketitle: test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: none in this lane unless daniel-parent asks; pipeline/CLI/Mac still need a re-pin and part (4).

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): revert whitespace-only Diagnostic constructor reflow

Restore original `push(Diagnostic::...)` line shape and hang `.with_help`
/ `.with_label` on the next line, instead of re-indenting the constructor
arguments by four spaces. Restore the `rejected entry_path` struct literal
to its original indent (only the three new fields added).

crates/compiler/src vs merge-base origin/main:
- git diff: 347 insertions(+), 59 deletions(-)
- git diff -w: 346 insertions(+), 58 deletions(-)
Previously 526+/186- vs 422+/82-. Remaining 1-line gap is expansion.rs
include-not-found, which changed skip() to Diagnostic::error (not whitespace).

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- cargo test --manifest-path crates/compiler/Cargo.toml --lib: test result: ok. 300 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: emit help.replacement as {source, text} via source_json.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): emit help.replacement as {source, text} via source_json

Replacement uses the same source object as labels[].source (path,
start_byte, end_byte) plus text, so it can target a different document
than the diagnostic (e.g. an included file). Proposal records why; the
JSON test asserts the new shape.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- cargo test --manifest-path crates/compiler/Cargo.toml --lib diagnostics:: : test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 297 filtered out

Next: drop help that restates the message; real help or none.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): drop help that restates the diagnostic message

`\foo is not supported in math mode` no longer gets `\foo is not
implemented in math mode`. Known text commands get a mode hint (`\foo is
a text command; use it outside math or inside \text{...}`); otherwise no
help. command_help/environment_help now return Option: package or
did-you-mean or spelling hints stay; generic "recognised but
unimplemented" restatements are omitted.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- cargo test --manifest-path crates/compiler/Cargo.toml --lib vocabulary:: : test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 297 filtered out
- --test diagnostic_codes: test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: undefined \ref wording should point at \ref{near}, not \label{near}.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): undefined \ref help points at \ref{near}, not \label{near}

The user must change the \ref key. When a nearby label exists, help is
"a label `near` exists; did you mean \ref{near}?". The no-near fallback
is unchanged.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- --test diagnostic_codes undefined_ref: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out

Next: unknown_command did-you-mean help.replacement on the command span.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): unknown_command did-you-mean help.replacement on the command span

`\alpah` keeps suggestion `\alpha` and now also help "did you mean \alpha?"
with replacement {source, text:"\alpha"} covering the exact command span.
with_optional_help does not overwrite that replacement. JSON test covers
the protocol compile_result object.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- --lib diagnostics:: : test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 298 filtered out
- --test diagnostic_codes: test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: incremental test that label and help.replacement spans shift.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#277): incremental test for label and help.replacement spans

shift_diagnostics maps label and replacement when an edit is before the
span, and returns None (invalidate) when the edit overlaps. Session
edits of `\alpah` keep both spans on the command bytes and match a clean
build; parser diagnostics still force today's full recompile.

Ran (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-structdiag):
- --lib incremental::tests::shift_diagnostics: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 304 filtered out
- --lib incremental::tests::edit_before_a_labelled: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 304 filtered out
- --lib incremental::tests::edit_inside_a_labelled: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 304 filtered out

Next: full compiler gates (--lib, diagnostic_codes, recovery, supported_latex, maketitle, then cargo test -p compiler).

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: d-q222 <[email protected]>
Co-authored-by: Cursor <[email protected]>
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged origin/main (2cf635b). #303 and #354 are on main; this lane no
longer needs its stacked pipeline-diag-forward display.rs code.

Conflict resolution:
- crates/flashtex-cli/src/main.rs: kept --fix/--dry-run and main's
  version_string (#420), collapse_repeats, and watch screen-clear. The
  post-fix re-check also uses collapse_repeats.
- crates/flashtex-cli/src/report.rs (add/add): kept main's structure
  (collapse_repeats) and ported this lane's `= help:` / `+` gutter
  suggestion rendering. Fold equality also compares suggestion.
- crates/render-pipeline/src/display.rs: took main's file. #354 already
  forwards compiler `code` exactly and runtime-v1 `suggestion`. This
  lane's default_code re-derivation was dropped (CLI reads suggestion
  from the pipeline Diagnostic; it does not need that re-derivation).

--fix still has no ambiguity policy. None existed; PR #444 is the
unique-closest-match rule, so the CLI applies whatever suggestion the
compiler emitted.

compile.rs auto-merged: suggestion copy plus main's missing-include
dedup. Tests in tests/cli.rs stayed at the end of the file.

Ran:
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-clifix cargo test --manifest-path crates/flashtex-cli/Cargo.toml
  unittests: test result: ok. 24 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  tests/cli.rs: test result: ok. 20 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  (multi_file_project_resolves_inputs_from_the_project_root now passes; #308 landed on main)
- cargo test --manifest-path crates/render-pipeline/Cargo.toml --lib
  test result: ok. 110 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Next: push this merge to origin/agent/daniel-parent/cli-fix.

Open questions: none in-scope. Ambiguous suggestions are compiler-side (#444, still open).

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
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.

2 participants