Engine symbols
What the compiler tells the editor. And what each record buys us.
Each compile can write a symbols sidecar (zitex-symbols/1, pdfTeX only) next to the PDF. Main already has commands and environments. PR #2453 adds eight record kinds the engine sees and a text parser cannot. Every example below is a real sidecar, decoded by the editor's own decoder.
- 8new record kinds in #2453
- 2already on main
- 30 / 39editor features wired today
- 216new records from a 27-line project
At the end of the run the engine walks its hash table and primitive table and writes every defined control sequence, with the definition site it recorded when the macro was assigned. Format symbols get sites from the format's .provsites sidecar.
What the engine records
name, kind- \foo; primitive, macro or control-sequence
params, body_preview- parameter text and body, as \show prints them
def- file, line, 1-based byte column; source_site for \let aliases
origin- package/class stem, body (the document) or format / unknown
internal- @-names and expl3 internals, hidden by default
Limits
- End-of-run state only: a macro defined inside a group is gone.
- origin names the defining file, not the package that loaded it (hpdftex.def reports body).
- Shorthand and font definitions (\chardef, \font) report no site.
What it unlocks in the editor
- ShippedCommand completion with signature and body, incl. package internals
symbols.ts - ShippedHover card: definition, origin package, alias source
symbols.ts - ShippedGo to definition of commands (F12)
symbols.ts - FutureOpen the .sty / .cls a library macro lives insites are recorded; needs a read-only source viewer
From the real sidecar: 58 symbols in the fixture (cut to the project's own; the full capture is 11.5 MB)
| name | params | body | def | origin |
|---|---|---|---|---|
\sys_rand_seed: | — | \tex_the:D \tex_randomseed:D | main.tex:1:1 | body |
\sys_if_shell_unrestricted:F | #1 | #1 | main.tex:1:1 | body |
\sys_if_shell:TF | #1#2 | #1 | main.tex:1:1 | body |
\mathbf | — | \select@group \mathbf \M@OT1 \OT1/cmr/bx/n | main.tex:24:1 | body |
\sys_if_shell:T | #1 | #1 | main.tex:1:1 | body |
provenance_status: loaded
Environments environments[]
A convenience list: every \foo / \endfoo pair where both are macros and \endfoo has a body. Structural, so a new package's environments appear without a name list.
What the engine records
name- environment name, no backslash
begin, end- the macro pair, \document / \enddocument
Limits
- Advisory: the symbols stay the source of truth.
- Internal pairs (@float) are listed; the client filters them.
What it unlocks in the editor
- Shipped\begin{ / \end{ completion from what was really loaded
symbols.ts - ShippedGo to definition of environments
symbols.ts - ShippedAuto-insert the matching \end{}
editor/autoEndEnvironment.ts
From the real sidecar: 77 environments (article, amsmath, glossaries, supertabular …)
| name | begin | end |
|---|---|---|
document | \document | \enddocument |
align | \align | \endalign |
theglossary | \theglossary | \endtheglossary |
supertabular | \supertabular | \endsupertabular |
Labels have no eqtb entry, so they are recorded as they happen: a hook on the aux \write at shipout keeps each \newlabel{key}{…}, and a hook on every \label call supplies where the key was typed, even when the key went through your own macro.
What the engine records
key- the label key
number, page- what \ref and \pageref will print, from the aux
anchor- hyperref anchor, or null
counter- equation, section, figure … (best effort)
def- where the \label{key} was typed
Limits
- Only labels that were shipped: one in a discarded float is absent, as it is from the .aux.
- A built key (\label{sec:#1}) gets the calling line but no column.
What it unlocks in the editor
- ShippedInlay hint on \ref: what it will print (“Fig. 4”, “(3)”)
lsp/labels.ts - Shipped\ref hover: number, counter, page
lsp/labels.ts - ShippedGo to definition of labels your macros made
lsp/labels.ts - ShippedDuplicate label marked on the hint (“3?”)
lsp/labels.ts - ShippedWorkspace symbols show each label's printed number
lsp/workspaceSymbols.ts - FutureDuplicate-label diagnostic for keys made by macrosthe duplicate writes are recorded; the diagnostic is text-only
From the real sidecar: 3 labels
| key | number | page | counter | def |
|---|---|---|---|---|
sec:intro | 1 | 1 | section | main.tex:23:23 |
eq:a | 1 | 1 | equation | main.tex:24:24 |
sec:chap | 2 | 1 | section | chapters/intro.tex:1:25 |
In the editor (real lsp/ output on these records)
hover on \ref{sec:intro}: §1 on page 1hover on \ref{eq:a}: Eq. (1) on page 1hover on \ref{sec:chap}: §2 on page 1inlay hint after \eqref{eq:a}: (1)
Every \ref-family command ends up looking up \csname r@<key>\endcsname. The engine hooks that lookup and keeps one record per place a key was typed, so a key passed through \myref{…} is found at the \myref line.
What the engine records
key- the label key (cleveref's @cref suffix removed)
kind- ref, eqref, cref, autoref, pageref … (best effort)
site- where the key's characters were typed
Limits
- A built key (\ref{sec:#1}) gets the right line, not the key's column.
- Probes (\@ifundefined) and the aux are filtered and counted, not recorded.
- One record per (key, site): no per-use count.
What it unlocks in the editor
- ShippedFind references (Shift-F12), incl. uses through your macros
lsp/references.ts - ShippedRename a label across files; engine-only sites reported, never edited blind
lsp/references.ts - ShippedUnused-label hint counts uses through \myref
unusedLabels.ts - ShippedReference counts in workspace symbols
lsp/workspaceSymbols.ts - FutureUndefined-reference check for keys a macro buildsundefined \ref is text-only today
From the real sidecar: 3 references
| key | kind | site |
|---|---|---|
eq:a | eqref | main.tex:25:12 |
sec:intro | ref | main.tex:25:29 |
sec:intro | ref | chapters/intro.tex:2:14 |
references_filtered: generated_file 3, probe 3, duplicate 0, no_file 0, internal 0
In the editor (real lsp/ output on these records)
Find References verifies exact sites against live source bytes.
A hook on macro expansion records each place one of YOUR macros was called: defined in a document file by a definer the text names (\newcommand, \def, \NewDocumentCommand, \newenvironment …). Kernel macros reassigned while your file is open are excluded.
What the engine records
name- the macro, as in symbols[].name
site- where its name was typed
count- expansions from that site over the run
Limits
- Names only a computation spells (\csname foo#1\endcsname) are not recorded.
- A \let alias of a format macro is not a user macro (amsthm's \endthm).
What it unlocks in the editor
- ShippedFind references and rename of your \newcommand macros
lsp/references.ts - FutureUnused-\newcommand hintdefinitions + uses are both recorded
- ShippedCall counts in the macro hover (hot macros)
lsp/macroUses.ts
From the real sidecar: 1 macro uses
| name | site | count |
|---|---|---|
\myref | main.tex:25:22 | 1 |
macro_uses_stats: origin_body_calls 4779, literal_calls 1, records 1, dropped 0
In the editor (real lsp/ output on these records)
Find References verifies exact sites against live source bytes.
Files files[]
Recorded at the two seams that also write the -recorder .fls input lines, so it is exactly the run's input set, each with the site that asked for it: \input in a chapter names the chapter, \RequirePackage names the .sty.
What the engine records
requested- the name as typed (plot, amsmath, chapters/intro)
resolved- ./path under the project, absolute for TEXMF
kind- tex, image, sty, cls, tfm … from the extension
site- the line that asked for it; null for the root
Limits
- The site search is textual: a name a macro computes can match the same name typed nearby.
- \openin probes are listed too (they are .fls inputs).
What it unlocks in the editor
- ShippedRoot detection with no magic comments
lsp/files.ts - ShippedCtrl-click paths built by macros or found via \graphicspath
lsp/files.ts - FutureUnused-asset report (project images the run never read)the read set is complete
- FutureJump into a loaded package's sourceresolved TEXMF paths are recorded
From the real sidecar: 60 files read
| requested | resolved | kind | site |
|---|---|---|---|
main.tex | main.tex | tex | — |
article | …/article.cls | cls | main.tex:1:16 |
localopt | localopt.sty | sty | main.tex:2:20 |
amsmath | …/amsmath.sty | sty | main.tex:3:13 |
graphicx | …/graphicx.sty | sty | main.tex:4:13 |
xcolor | …/xcolor.sty | sty | main.tex:5:13 |
glossaries | …/glossaries.sty | sty | main.tex:6:22 |
by kind: sty 29, tex 6, def 4, cfg 3, tfm 3, pfb 3, cnf 2, ldf 2, aux 2, map 2, fmt 1, cls 1, clo 1, mkii 1
In the editor (real lsp/ output on these records)
include closure: root main.tex, members chapters/intro.tex, main.texopen chapters/intro.tex → rooted at main.tex
xcolor stores each colour in a macro \color@<name>. At closeout the engine scans for them and reads back what xcolor stored, so HTML FF8800 arrives as rgb 1,0.53333,0 and a palette appears exactly when a package option loaded it.
What the engine records
name- colour name
model, value- what xcolor stored (rgb, cmyk, gray)
def- your \definecolor / \colorlet line, or the palette file
origin- body, xcolor, dvipsnam, svgnam …
alias_of, series- the \colorlet target; \definecolorseries method, step and reset
Limits
- Only colours visible at the end of the run (not one defined in a group).
- pdfTeX only; plain color.sty under another driver reports null.
What it unlocks in the editor
- ShippedSwatches on \definecolor, \textcolor, mixes, tikz fill=
lsp/colors.ts - ShippedColour-name completion incl. dvipsnames / svgnames palettes
lsp/colors.ts - ShippedAlias chain and series step in the colour hover (accent → brand)
lsp/colors.ts
From the real sidecar: 21 colours
| name | model / value | origin | def |
|---|---|---|---|
brand | rgb 1,0.53333,0 | body | main.tex:7:1 |
accent | rgb 1,0.53333,0 | body | main.tex:8:1 |
red | rgb 1,0,0 | xcolor | xcolor.sty:1444:1 |
green | rgb 0,1,0 | xcolor | xcolor.sty:1444:1 |
blue | rgb 0,0,1 | xcolor | xcolor.sty:1444:1 |
brown | rgb 0.75,0.5,0.25 | xcolor | xcolor.sty:1444:1 |
\ProcessOptions erases what \DeclareOption made, so a scan cannot recover options. A kernel hook in the zitex format leaves one marker macro per \DeclareOption (and per top-level \ExecuteOptions default); the closeout scan turns the markers into records.
What the engine records
package, kind- what was loaded; package or class
option- the option; "*" is the \DeclareOption* handler
default- on unless overridden (\ExecuteOptions)
def- the \DeclareOption line
options_hook- false = format without the hook: unknown, not none
Limits
- Needs the hooks format (all production formats have it; stock pdflatex.fmt does not).
- \DeclareKeys options are l3keys and land in keys[], not here.
What it unlocks in the editor
- Shipped\usepackage[…] / \documentclass[…] completion
lsp/keyvals.ts - ShippedDefaults marked; the \DeclareOption* handler not offered
lsp/keyvals.ts - FutureUnknown-option diagnostic (silent for packages with a * handler)both facts are recorded
From the real sidecar: 24 options (options_hook: true)
| package | option | flags | def |
|---|---|---|---|
localopt (package) | beta | default | localopt.sty:4:1 |
localopt (package) | alpha | — | localopt.sty:3:1 |
localopt (package) | * | \DeclareOption* handler | localopt.sty:5:1 |
article (class) | a4paper | — | article.cls:55:1 |
article (class) | a5paper | — | article.cls:58:1 |
article (class) | b5paper | — | article.cls:61:1 |
In the editor (real lsp/ output on these records)
\usepackage[|]{localopt} offers: beta, alpha\documentclass[two|]{article} offers: twoside, twocolumn
A key is a macro with a known name pattern: KV@<family>@<key> for keyval, key code > <module>/<key> for l3keys, pgfk@<path>/.@cmd for pgfkeys. The closeout scan reads them back with defaults, types and choices; token stamps place each key where it is written.
What the engine records
system, family, key- keyval, xkeyval, l3keys or pgfkeys; Gin, mymod …
type, choices- bool, code, choice (with its values)
has_default, default- no default = the key needs a value
usage- load / preamble: only usable at load time
value_type, value_key, package- emitted, not read by the webapp yet
Limits
- Keys defined inside a group, or built with \csname and never defined, are missed.
- An xkeyval prefix family with no key that has a default stays invisible.
What it unlocks in the editor
- ShippedKey completion for \includegraphics, \hypersetup, tikz, tcolorbox …
lsp/keyvals.ts - ShippedChoice values after =, true/false for bools
lsp/keyvals.ts - ShippedYour own \define@key / \keys_define:nn families
lsp/keyvals.ts - FutureValue checking (int / dim keys), unknown-key diagnosticvalue_type is emitted, not decoded
From the real sidecar: 103 keys
| system / family | key | type | value | def |
|---|---|---|---|---|
keyval / myfam | size | — | required | main.tex:11:1 |
l3keys / mymod | mode | choice: fast, slow | required | main.tex:16:5 |
l3keys / mymod | level | code | default 3 | main.tex:17:5 |
keyval / Gin | width | — | required | graphicx.sty:65:1 |
keyval / Gin | keepaspectratio | — | default true | graphicx.sty:69:1 |
by family: glossaries.sty 69, Gin 31, myfam 1, mymod 2 · scan_stats: colors 21, options 491, keyval 148, xkeyval 7, l3keys 191, pgfkeys 0, glossary 1
In the editor (real lsp/ output on these records)
\includegraphics[|] offers: natheight, read, origin, bbllx, bblly, bburx, bbury, natwidth …
Glossary and acronyms glossary[]
Every glossaries definition ends in \gls@defglossaryentry, which stores each field in glo@<label>@<field>. The closeout scan reads them back; token stamps on the label say where the key was typed, also through your own macro.
What the engine records
key- the entry label
kind- acronym (has a long form) or entry
short, long, description- stored field values, null when empty
type, category- which glossary; glossaries-extra category
def- the line the key is typed on
Limits
- Not the acronym package: \acrodef only exists from the next run, via the .aux (the editor's text scan covers it).
- Listed whether or not it is used.
What it unlocks in the editor
- ShippedCompletion in \gls{…}, \ac{…}, \acrfull{…} …
lsp/glossary.ts - ShippedHover (API — application programming interface)
lsp/glossary.ts - ShippedGo to definition of entries, incl. ones a macro made
lsp/glossary.ts - FutureUnused-entry hintuses are not recorded yet
From the real sidecar: 1 glossary entries
| key | kind | short | long | def |
|---|---|---|---|---|
api | acronym | API | application programming interface | main.tex:21:13 |
Where the examples come from
The sample project
Three files, compiled twice by the shipped WASM engine with -dump-symbols. The sidecar is checked in at lib/zitex-intellisense/__fixtures__/real-records/main.symbols.json and imported by this page as is; realSidecar.unit.test.ts fails if the engine's contract moves.
1\documentclass{article} 2\usepackage[alpha]{localopt} 3\usepackage{amsmath} 4\usepackage{graphicx} 5\usepackage{xcolor} 6\usepackage[acronym]{glossaries} 7\definecolor{brand}{HTML}{FF8800} 8\colorlet{accent}{brand} 9\newcommand{\myref}[1]{(see \ref{#1})} 10\makeatletter 11\define@key{myfam}{size}{\def\my@size{#1}} 12\makeatother 13\ExplSyntaxOn 14\keys_define:nn { mymod } 15 { 16 mode .choices:nn = { fast , slow } { } , 17 level .int_set:N = \l_tmpa_int , 18 level .default:n = 3 19 } 20\ExplSyntaxOff 21\newacronym{api}{API}{application programming interface} 22\begin{document} 23\section{Intro}\label{sec:intro} 24\begin{equation}\label{eq:a} x \end{equation} 25See \eqref{eq:a} and \myref{sec:intro}, via the \gls{api}. 26\input{chapters/intro} 27\end{document}
1\section{Chapter}\label{sec:chap} 2Back to \ref{sec:intro}.
1\NeedsTeXFormat{LaTeX2e} 2\ProvidesPackage{localopt} 3\DeclareOption{alpha}{\def\localopt@a{1}} 4\DeclareOption{beta}{\def\localopt@b{1}} 5\DeclareOption*{\PackageWarning{localopt}{unknown \CurrentOption}} 6\ExecuteOptions{beta} 7\ProcessOptions\relax