Skip to content

Add a Rust grammar to quarto-highlight (rust / rs) - #662

Merged
cscheid merged 1 commit into
mainfrom
feature/bd-202u5bld-add-rust-grammar-quarto
Sep 8, 2026
Merged

Add a Rust grammar to quarto-highlight (rust / rs)#662
cscheid merged 1 commit into
mainfrom
feature/bd-202u5bld-add-rust-grammar-quarto

Conversation

@cscheid

@cscheid cscheid commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

rust and rs fenced code blocks rendered as <pre class="rust"> with no highlight spans, in both q2 render and the WASM preview path: the built-in registry in quarto-highlight carried 13 grammars and Rust was not among them.

This wires tree-sitter-rust 0.24.2 in as a built-in with canonical key rust and alias rs, using the crate's own HIGHLIGHTS_QUERY (no vendored copy, per the drift-free rule; resources/highlights/ exists only for Julia, whose crate lacks the constant). Injections stay empty, matching the captures-only resolver. All 20 capture names the query emits already resolve through the longest-prefix fallback in the SCSS theme translator and the LSP token legend, so no theme or legend changes.

Strand: bd-202u5bld (parent bd-n7x2). Plan with the full scouting table and evidence: claude-notes/plans/2026-09-08-rust-highlight-grammar.md.

Tests (written first, verified failing on the unregistered class)

  • all_languages.rs: rust / rs cases
  • builtin-snippets.json: Rust entry (also feeds the hub-client vitest WASM harness)
  • smoke-all/highlighting/09-builtin-rust.qmd: end-to-end through quarto render, asserting sourceCode rust, sourceCode rs, hl-keyword on fn, hl-function-macro on println

Snapshots: 1 added, 0 modifiedintegration__golden__rust.snap, reviewed span by span (doc comment, fn, function name, parameter, &str as type.builtin, String as type, format! as function.macro, string, brackets; all node-exact).

Verification

  • cargo xtask verify steps 1–7 green, including the hub-client WASM build (the grammar's C scanner uses the same isw* calls as bash and links on wasm32 via wasm-c-shim).
  • Step 8 (hub-client test:ci) fails only on the 23 pre-existing Node 26 localStorage failures tracked in bd-lh30hlvd, reproduced identically on clean main. test:wasm (133) and test:integration (119) pass when run directly.
  • End to end: q2 render on a probe emits sourceCode rust / sourceCode rs blocks with hl-keyword, hl-type-builtin, hl-function-macro spans; q2 preview with freshly rebuilt WASM highlights the same probe (inspected in headless Chromium).

Upstream-query behaviours inherited from tree-sitter-rust, noted in the plan: integer literals are captured as constant.builtin; let-bound names and -> carry no capture.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UMfCmnsXHFcooUFMaRLxoe

`rust` and `rs` fenced blocks rendered as `<pre class="rust">` with no
highlight spans in both `q2 render` and the WASM preview path: the
built-in registry carried 13 grammars and Rust was not one of them.

Wire tree-sitter-rust 0.24.2 in as a built-in with canonical key `rust`
and alias `rs`, using the crate's `HIGHLIGHTS_QUERY` (no vendored copy
under resources/highlights/, per the drift-free rule). Injections stay
empty, matching the captures-only resolver. All 20 capture names the
query emits already resolve through the longest-prefix fallback in the
SCSS theme translator and the LSP token legend, so no theme or legend
changes.

Tests (written first, verified failing on the unregistered class):
- all_languages: `rust` / `rs` cases
- builtin-snippets.json: rust entry (also feeds the hub-client vitest
  WASM harness)
- smoke-all/highlighting/09-builtin-rust.qmd: end-to-end through
  `quarto render`, asserting `sourceCode rust`, `sourceCode rs`,
  `hl-keyword` on `fn` and `hl-function-macro` on `println`

Snapshots: 1 added, 0 modified —
tests/integration/snapshots/integration__golden__rust.snap. Reviewed
span by span: doc comment, `fn`, function name, parameter, `&str` as
type.builtin, `String` as type, `format!` as function.macro, string,
brackets. All node-exact.

Verification: `cargo xtask verify` steps 1–7 green (including the
wasm32 link of the grammar's scanner in the hub-client build). Step 8
fails only on the 23 pre-existing Node 26 `localStorage` vitest
failures (bd-lh30hlvd), reproduced identically on clean main;
`test:wasm` (133) and `test:integration` (119) pass when run directly.
End-to-end: `q2 render` and a fresh-WASM `q2 preview` both highlight
the probe; evidence in the plan.

Plan: claude-notes/plans/2026-09-08-rust-highlight-grammar.md

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UMfCmnsXHFcooUFMaRLxoe
@posit-snyk-bot

posit-snyk-bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cscheid
cscheid merged commit 69504df into main Sep 8, 2026
10 checks passed
@cscheid
cscheid deleted the feature/bd-202u5bld-add-rust-grammar-quarto branch September 8, 2026 20:16
cscheid added a commit that referenced this pull request Sep 8, 2026
Resolves the expected overlap with the theme-compile-error work:
theme_diagnostic keeps both the Q-14-7 (InvalidScssFile) and Q-14-8
(InvalidBrandFontWeight) arms and the Q-14-6 catch-all replaces this
branch's old code-less fallback; SassError::with_location and
sass_error_location cover both new variants; the errors sidebar lists
Q-14-6, Q-14-7, Q-14-8 in code order. The brand-file bind candidate and
main's fallback_location coexist in sass_error_to_parse_error_at.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NE1UEmUUagZwZ5APMZYfra
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