Skip to main content

Module define

Module define 

Source
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_definitions extracts. Signatures stay range-free so the document_signatures salsa 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§

DefSiteKind
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 name is 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’s missing-required-argument rule skips partial applications like \newcommand{\bold}{\textbf}) share the scanner’s one name list instead of duplicating it.
scan_definition_sites
Scan root for user command/environment definitions and return their sites, in document order. Same recognizer set and name resolution as scan_definitions (the [DefKind] dispatch and [resolve_command_def] sibling heuristic), but keeping every definition — no last-wins collapsing, since a \renewcommand of an earlier definition is still a definition site the user may navigate to or rename.
scan_definitions
Scan root for user command/environment definitions and return their extracted signatures. Names already defined earlier in the document are overwritten, so a later \renewcommand wins — TeX’s last-definition-wins, modulo execution order we do not track.