Skip to content

compiler: recognize \lstinputlisting[options]{file} as a literal listing (GH-LSTINPUTLISTING) - #586

Merged
GoKubar merged 1 commit into
agent/daniel-parent/lstlisting-braced-optionsfrom
agent/daniel-muse-lead/lstinputlisting
Sep 15, 2026
Merged

GoKubar merged 1 commit into
agent/daniel-parent/lstlisting-braced-optionsfrom
agent/daniel-muse-lead/lstinputlisting

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Scope

Stacked on #542 (this PR's base branch) — builds on its \lstlisting/\lstlistoflistings option-parsing and listing-numbering work rather than duplicating it. Do not diff this PR against main; diff against #542's head.

\lstinputlisting[options]{file} (listings package) now recognizes and resolves the file, reusing \input/\include's exact file-resolution logic (verified by reading P::include first: token_text + trim, path_is_safe gate, document_by_path lookup with .tex appended as a fallback if the bare name isn't found — confirmed this compiler does append .tex, matching real listings.sty behavior). The optional [options] argument goes through the SAME parser #542 fixed for lstlisting (braced-] handling included), with the same warn-and-typeset-literally fallback. The file's raw bytes become one Block::Verbatim, identical in shape to an inline \begin{lstlisting} block, so it counts for \lstlistoflistings purposes at the compiler level (there is no separate compiler-side listing counter to update — the render-pipeline owns that). Missing/unsafe paths get a clear diagnostic (listed file not found: looked for 'X' and 'X.tex'), matching \input's error style — no panic, no silent no-op.

Overlap check

coord.py claims — no other claim on \lstinputlisting. Confirmed this branch's own diff (vs. #542's head, not main) touches only crates/compiler/** and docs/user/compiler.md — nothing under crates/render-pipeline/.

Test results

Focused run (cargo test --test lstinputlisting):

test caption_option_is_accepted_the_same_way_as_lstlisting ... ok
test listing_count_increments_for_listoflistings_purposes ... ok
test missing_file_reports_a_clear_diagnostic ... ok
test file_content_appears_as_a_literal_listing ... ok
test result: ok. 4 passed; 0 failed

Independent mutation check (supervisor-run, fresh CARGO_TARGET_DIR): disabled the dispatch arm → file_content_appears_as_a_literal_listing FAILED, tripping the codebase's own internal consistency assertion (assertion failed: !BUILT_INS.contains(&name)); restored → passes. Full cargo test --release in crates/compiler (lane's own run): 58 suites, 674 passed, 0 failed.

Entry-point repro (via flashtex_compiler::protocol::handle_line, a two-document payload with main.tex + code.py): compiling \lstinputlisting[caption=Example]{code} returns only the expected "options are not implemented" warning (options genuinely aren't wired to formatting yet, matching lstlisting's own scope) — code.py's content is typeset literally with source spans pointing at code.py, and the surrounding Before./After. paragraphs stay intact.

Not done

Render-pipeline \lstlistoflistings polish: crates/render-pipeline/src/listings.rs::scan counts/numbers/captions listings by scanning source text for \begin{lstlisting} and matching by body-span ranges within the SAME document. A \lstinputlisting-produced block carries spans in the INCLUDED file's document, so pipeline scan won't currently pick it up for caption/number styling or the LoL page — the content still renders as literal typewriter lines (this PR's compiler lowering), just without pipeline-side numbering/captioning. Extending listings::scan to recognize \lstinputlisting is a separate render-pipeline slice, proposed as a follow-up.

🤖 Generated with Claude Code

What changed:
- parser: new \lstinputlisting[options]{file} arm. The {file} argument
  resolves with exactly the \input/\include rules (path_is_safe gate,
  document_by_path lookup with .tex appended as fallback); the file is
  never parsed, its bytes become one Block::Verbatim like an inline
  lstlisting body, so file listings count for \lstlistoflistings
  purposes exactly like inline ones. Options run through the same
  optional_bracket_argument parser with the same warn-and-typeset-
  literally fallback. Missing files report 'listed file not found'
  with the same error/recovery/help shape as a missing \input.
- vocabulary: lstinputlisting is a listings command; BUILT_INS so the
  expansion engine passes it through as a host command.
- supported inventory (+ regenerated supported-latex.json, coverage
  docs, Mac bundled copy): new [options]{file} entry.

What was run:
- cargo test --release --test lstinputlisting: 4 passed
- mutation check (dispatch arm reverted): 4 failed with
  '\lstinputlisting is not supported by this compiler version'; restored: 4 passed
- cargo test --release (crates/compiler): 58 suites, 674 passed, 0 failed
  (base before change: 57 suites, 0 failures)
- entry-point repro through flashtex_compiler::protocol::handle_line
  (temporary test, deleted): file bytes typeset with code.py spans,
  no unknown_command

Implementation-Agent: muse-spark-1.3-contributor
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent review (subagent)

Verdict: READY (stacked on open #542 — see stacking note at the end)

This is a fresh review; no prior daniel-parent review (subagent) comment exists on this PR.

What I checked

  • muse-precheck.sh 586: no forbidden-path hits, both supported-latex.json copies identical, no vendor/ files, CI green on the shells that had finished (macOS shells were still queued at review time; ubuntu shells and the inventory-sync check all passed).
  • Read the full diff (crates/compiler/src/parser.rs, supported.rs, vocabulary.rs, the two supported-latex.json mirrors, docs/user/compiler.md, and the new tests/lstinputlisting.rs). compiler: recognize \lstinputlisting[options]{file} as a literal listing (GH-LSTINPUTLISTING) #586's own diff touches only crates/compiler/**, apps/mac/.../supported-latex.json (generated mirror), and docs/user/compiler.md — nothing in crates/render-pipeline/ and nothing under vendor/.
  • Real-oracle comparison with /Library/TeX/texbin/pdflatex (\usepackage{listings}, TeX Live 2026):
    • \lstinputlisting[caption=Example]{code.py} → real listings shows the literal file bytes plus a numbered "Listing 1: Example" caption. FlashTeX's version shows the same literal bytes but only a diagnostic warning for the options (no caption/numbering) — this is the same, already-accepted scope limitation \begin{lstlisting}[caption=...] already has in this compiler, and the PR's own "Not done" section discloses it accurately for the \lstinputlisting case too.
    • Extension fallback: I tested \lstinputlisting{code} against a real code.py (no .tex) with real pdflatex — it fails with ! Package Listings Error: File 'code(.tex)' not found., confirming real listings does apply TeX's default-.tex-extension search when the given name has no extension. So this PR's reuse of \input/\include's exact-name-then-name.tex fallback is not just "borrowed for convenience," it matches real pdflatex behavior for the untested-extension case.
    • path_is_safe, the "requires a non-empty project-relative path" and "file not found" diagnostics all mirror include()'s existing logic byte-for-byte (I diff'd the two functions side by side); the one difference is the missing-file diagnostic span is span.merge(argument_span) here vs. just span in include() — a strictly more precise span, not a behavior change.
  • Confirmed the new tests are not vacuous: \lstinputlisting does not appear anywhere in parser.rs at the merge-base (compiler: a braced ] does not end lstlisting's options; \lstlistoflistings is listings' #542's branch tip pre-compiler: recognize \lstinputlisting[options]{file} as a literal listing (GH-LSTINPUTLISTING) #586), so pre-fix it would fall through to the generic "\{name} is not supported by this compiler version" diagnostic path — materially different from what every new test asserts (specific diagnostic text, Block::Verbatim count, literal content). I also found the debug_assert!(!BUILT_INS.contains(&name)) at parser.rs:7307 that the PR body's mutation-check claim ("disabling the dispatch arm trips … assertion failed") refers to — it's real, so that claim checks out.
  • Built the PR in a detached worktree (git fetch origin pull/586/head + worktree add --detach) and ran the narrow filter:
    • cargo test -p compiler --test lstinputlisting → 4/4 passed.
    • Full cargo test --release in crates/compiler → all suites green, 0 failed (matches the PR body's claimed clean full-suite run).
  • PR body repro: the quoted cargo test --test lstinputlisting output matches what I actually ran. The handle_line-based entry-point repro description is consistent with the parse_project-level tests I ran directly (same code path, same diagnostic/one-Block::Verbatim shape).

Non-blocking note (for the integration lane, not a finding against #586)

#586's single commit (030c83ee) sits on 57e76193, but the live tip of its base branch agent/daniel-parent/lstlisting-braced-options is now one commit ahead, at dce408c7 ("compiler: test lstlisting options' backslash escape"). I checked that commit — it only adds tests to expansion.rs/parser.rs's mod tests for #542's own escape handling, no logic changes, so there is no functional divergence and gh pr diff 586 is still accurate. Still, #586 will want a trivial rebase onto #542's current tip before merge.

Stacking

This PR is stacked on open PR #542 (branch agent/daniel-parent/lstlisting-braced-options). #586's own readiness above is independent of #542's review status — I did not re-review #542's own changes — but the merge order matters: #542 needs to land (or #586 rebase onto its current tip, see note above) before #586 can go into main.

@GoKubar
GoKubar merged commit f89ef10 into agent/daniel-parent/lstlisting-braced-options Sep 15, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/daniel-muse-lead/lstinputlisting branch September 16, 2026 04:16
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