Expand description
Scan a document for user definitions — \newcommand/\newenvironment and
the xparse \NewDocument… family — and extract their argument signatures into
a per-document SignatureDb. The scanner reads declared argument shapes,
but neither interprets replacement text nor executes definitions.
A single whole-tree walk (mirror of super::builder::build) collects every
definition; the result overlays the built-in DB via Signatures (scanned
first). The greedy parser attaches definitions like any other command, so they
surface as plain COMMAND descendants — those inside a comment or a verbatim
body never parse to a COMMAND, so they are skipped for free.
§Both name forms
For command definitions we extract both name forms: the braced
\newcommand{\foo}… and the unbraced \newcommand\foo…. The unbraced form
parses awkwardly under greedy attachment — \foo becomes a sibling COMMAND
and the [n]/replacement group attaches to it, not to \newcommand — so
\newcommand itself has no name group. We recover it with a scanner-side sibling
heuristic ([resolve_command_def]): when a definition command has no attached
group, the name and argument shape are read off the immediately-following sibling
COMMAND. This stays in the scanner — no parser change — so the parser remains
meaning-free (decision #2). Environment names are brace-delimited text, never a
bare control word, so they have no unbraced form to recover.
Structs§
- DefSite
- One user definition’s location — the range-bearing sibling of the signature
facts
scan_definitionsextracts. Signatures stay range-free so thedocument_signaturessalsa query backdates on pure-offset edits; definition sites feed LSP navigation (goto-definition, references, rename), which needs byte ranges and recomputes them per request off the memoized tree.
Enums§
- DefSite
Kind - Which namespace a scanned definition site names. Commands and environments live in disjoint TeX namespaces, so a name match is only meaningful within a kind.
Functions§
- is_
definition_ command - Whether
nameis a definition command the scanner recognizes (\newcommand/\def/xparse families; see [DefKind]). Exposed so consumers that must treat a definition’s arguments as code carried, not executed (the linter’smissing-required-argumentrule skips partial applications like\newcommand{\bold}{\textbf}) share the scanner’s one name list instead of duplicating it. - scan_
definition_ sites - Scan
rootfor user command/environment definitions and return their sites, in document order. Same recognizer set and name resolution asscan_definitions(the [DefKind] dispatch and [resolve_command_def] sibling heuristic), but keeping every definition — no last-wins collapsing, since a\renewcommandof an earlier definition is still a definition site the user may navigate to or rename. - scan_
definitions - Scan
rootfor user command/environment definitions and return their extracted signatures. Names already defined earlier in the document are overwritten, so a later\renewcommandwins — TeX’s last-definition-wins, modulo execution order we do not track.