Repository navigation
feat: add hover with Lua 5.2 manual text and EEex-Docs links - #6
Merged
Merged
Conversation
Move the pinned tarball URL, its published SHA-256, the download into .cache/lua and the verification from build.mts into tarball.mts, so the Lua manual data generator (next commits) uses the same verified source instead of a second copy of the logic. tarball.mts throws instead of exiting, so each caller reports failures under its own annotation title. No behaviour change: `npm run build:wasm -- --check` still reports that third_party/lua52/dist matches a fresh build byte for byte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
plan.md requires help text that keeps the wording and formatting of the Lua 5.2 reference manual. Add a pure converter from the manual's HTML to Markdown (for hovers) and plain text (for clients without Markdown). It accepts exactly the HTML the library entries of chapter 6 use (inventoried from lua-5.2.4/doc/manual.html: p, pre, ul/li, code, em, b, a href="#…", a name, sup; entities · § – π < >, plus &, " and the © of the copyright line) and throws on anything else, so a manual that changes shape fails the generator instead of producing wrong text: - paragraphs keep their text; whitespace collapses as in HTML, also across element boundaries, and a non-breaking space stays one; - <pre> becomes a fenced block, verbatim; list items keep their nested code blocks and paragraphs; - links into the manual become absolute links to https://www.lua.org/manual/5.2/manual.html#…; - text Markdown would interpret (* _ [ ] < > & ~ | ` \ and a leading #, -, + or 1.) is escaped. Three constructs have no Markdown equivalent; hovers render Markdown without HTML in VS Code, and other clients may not render HTML at all: - <sup> becomes Unicode superscripts (2³², eˣ); - <em> inside <code> (`%<em>d</em>` in string.gsub) becomes an emphasized code span of its own: `%`*`d`*; - <em> inside <pre> (the placeholder `body` in the ipairs and pairs examples) keeps its text without emphasis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `npm run lua-manual`, which writes data/lua52/manual.json from lua-5.2.4/doc/manual.html in the SHA-256-verified tarball (the release of the embedded compiler). `--check` fails when the committed file differs from a fresh run; `--compare-online` audits the online manual. Only the libraries the engine opens are included (CLAUDE.md §7, IESDP "Engine Lua globals"): §6.1 basic functions (24 entries), §6.4 string, §6.5 table, §6.6 math, §6.7 bit32 and §6.10 debug, each with its module table, 106 entries in all. Coroutines, modules (`require`), io and os are left out. Each entry keeps the manual's heading verbatim (`string.format (formatstring, ···)`), its anchor, and its text as Markdown and plain text (previous commit). Links point to https://www.lua.org/manual/5.2/manual.html, the URL plan.md names. The generator fails, with the section and entry at fault, when a section, an entry heading or a module anchor is missing, an entry belongs to another library, or the HTML is outside the supported subset. Audit (`--compare-online`, 2026-10-29): the sections and all 106 entries generated from https://www.lua.org/manual/5.2/manual.html are identical to those from the tarball. The only difference is the copyright line: 2011–2015 in the tarball, 2011–2013 online (that page was last modified on 2019-08-29). The tarball stays the source: it is pinned and verifiable, and it is the newer text. Tests check the committed data: the provenance, the section list, the per-section counts, the absence of coroutine/io/os/package/require, and golden text for math.huge, math.exp, select, bit32.extract, table.sort, debug.sethook, collectgarbage, string.gsub and the string module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New job "Lua 5.2 manual data is current" runs `npm run lua-manual -- --check`, so data/lua52/manual.json can only change together with the generator or the pinned tarball. It is cheap: - it runs only when scripts/lua-manual/, data/lua52/, third_party/lua52/tarball.mts or ci.yml change (new `manual` output of the `changes` job; every job runs when there is no usable base); - no `npm ci`: the generator uses only Node built-ins and `tar`; - 5-minute timeout. The Lua tarball now has its own cache, keyed by the hash of tarball.mts (which pins the URL and SHA-256), shared by this job and the `wasm` job. Before, it was stored inside the emsdk cache entry. The emsdk cache now holds only .cache/emsdk; its path changed, so the first run after this commit misses it once. Errors are reported as `::error title=Lua manual data::` annotations naming the file and the command that fixes it. Checked with actionlint 1.7.12 (shellcheck is not installed locally, so the run steps were not shell-linted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In Lua 5.2 a free name `x` means `_ENV.x` (manual §2.2). While a local, parameter or `for` variable named `_ENV` is visible, `x` is a field of that table, not of the global environment. Record such identifiers in the new `ScopeAnalysis.environmentFields`, so that hover does not describe `print` or `string` from the standard library when they can be anything. They stay in `globals` by name, so navigation, rename and symbols are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hover needs two things the syntax layer did not provide yet: - members.ts: the field and method names used in expressions (`string.format`, `s:rep()`), sorted by offset, with the expression and chunk they belong to, and `memberAt` to find one by position. Names in `function a.b:c()` and table constructor keys define fields and are not included. - signatures.ts: the statement that declares or assigns each name (`local function f(…)`, `local x = …`, `function x(…)`, `x = …`), with the value in the same position, for describing variables. Both are built lazily once per parsed document (WeakMap, dropped with it), like the variable index of navigation.ts, on a new generic walker (walk.ts) over statements and expressions. `identifierAt`, the binary search behind `targetAt`, is now exported so variables and members share the rule that a cursor just after a name selects it. `parameterList` moves from symbols.ts to signatures.ts; outline details are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hover will show a few labels of the server's own (maintainer decision:
localized on the server, from `InitializeParams.locale`, so that every
LSP client benefits, not only VS Code). The server runs outside VS Code
and cannot use `vscode.l10n`, so:
- l10n/server/messages.json (English) and messages.<locale>.json for
the 14 VS Code display languages are bundled into the server by
esbuild through JSON import attributes (checked with tsc, ESLint,
Node's type stripping for the unit tests, and esbuild);
- src/server/l10n.ts resolves the requested locale (exact match, else
the bare language: `de-AT` → `de`; regional variants are never
substituted, so `pt-PT` and `zh-Hans` get English), substitutes `{n}`
placeholders, and falls back to English per key;
- the list of locales moves from scripts/check-l10n.mts to
src/shared/locales.ts, so the server and the check share it;
- `npm run check-l10n` gains step 6 (each server table has exactly the
English keys, with code spans and placeholders unchanged, and exists)
and step 7 (every English key is used in src/server). Both were
checked to fail on a missing file, a missing or changed key and an
unused key.
The tables are empty in this commit; hover adds its keys.
.vscodeignore now ships only l10n/bundle.l10n*.json, which the client
loads at run time; the server tables are already inside server.js
(`vsce ls` and the CI allow-list are unchanged).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Decide what a hover describes, without rendering it yet. knowledge.ts loads what the server knows about names it does not see defined: - the Lua 5.2 manual entries (data/lua52/manual.json), with their section and a link into https://www.lua.org/manual/5.2/manual.html; - the engine's replacement of `print` (IESDP "Engine Lua globals", commit 38e7532: "Replacement for Lua's print, registered by the engine's Lua bootstrap", with no behaviour given); - EEex-Docs names and links (data/eeex/eeex-functions.json and game-lua-functions.json; no text, as EEex-Docs has no license). Game structures are C++ types that Lua code never names, so they are not looked up and not bundled. resolve.ts maps the name under the cursor to a target: - a local: its declaration and how it gets its value; - a global, shared by the chunks of a .menu file: the document's own first assignment wins (an EEex-Docs link is kept); otherwise the engine's `print` note, the manual, EEex-Docs, or a bare global. io, os, require and coroutine get no documentation: the engine does not open those libraries; - a field or method: `string.format`, `_G.string.format`, `("x"):rep()` (strings index the string table, manual §6.4), `C:AddGold()` and `C.AddGold`, `EEex_Options_Option.new`. Fields of locals and of tables the document builds get no hover, as does any name resolved through a local `_ENV`, and `_ENV` itself. `TargetHit` from navigation.ts now also carries the chunk index that targetAt already knew. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turn a hover target into text, in the format the client asks for: - the name as Lua: a ```lua block in Markdown (`local function f(a, b, ...)`, `local g = function(c)`, `(parameter) a`, `(for variable) i`, `(global) function G(a)`), or the manual's heading verbatim (`string.format (formatstring, ···)`); - the manual text, verbatim (Markdown or plain text from data/lua52/manual.json); - the source: `Lua 5.2 Reference Manual, §6.4 – String Manipulation`, or the EEex-Docs section title (`EEex Functions`, `EE Game Lua Functions`), linked to the entry. For `print`, the manual text is replaced by a note that the engine replaces the function, linking IESDP's "Engine Lua globals" page. The server's own four strings (`parameter`, `for variable`, `global` and that note) are added to l10n/server/ in English and the 14 VS Code display languages (machine-produced, like the existing translations; review welcome). `npm run check-l10n` passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hovers will quote the Lua 5.2 reference manual, whose copyright line reads "Freely available under the terms of the Lua license". When the esbuild metafiles show data/lua52/manual.json in a bundle, the notices gain a section with the manual's title, source, copyright line (read from the data file) and the Lua license text already kept in third_party/lua52/licenses/lua.txt. Nothing bundles the file yet, so THIRD_PARTY_NOTICES.md is unchanged (`npm run notices -- --check` passes); the hover commit regenerates it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Register `textDocument/hover` and advertise `hoverProvider`. The handler follows the other features: it uses the shared parse cache, checks cancellation before its synchronous work, and logs and returns null on any error. It answers in the first format of the client's `hover.contentFormat` it can produce (Markdown or plain text; plain text when the client lists none), with the server messages of the client's `locale`, and gives the range of the name. Integration tests (original fixtures hover.lua and HOVER.MENU) cover the manual text and link of string.format, a local function, a parameter, a `for` variable, a global function, the print note, an EEex-Docs link, a shadowed `string`, no hover on a keyword, and a .menu global assigned in another chunk. THIRD_PARTY_NOTICES.md now credits the Lua 5.2 manual, which the server bundle quotes. Measured on the game's UI.MENU (588 KB, 16,425 names; local, not committed), Node 24.22.1, five runs: - first hover of a parsed document (builds the member index and the declaration sites): 4.7 ms; - each name after that: 0.09–0.11 ms median, 4.4 ms at worst, against the 50 ms budget; - loading the hover modules and their data: 14.7 ms, once at startup. Size: dist/server/server.js 420,851 → 662,479 bytes (manual text 81.4 KB, EEex-Docs names and links 146.7 KB, code and messages the rest); VSIX 273.1 → 308.5 KB; installed size 950.05 KB → 1.16 MB. Stripping the shared URL prefixes of the EEex-Docs links would save about 58 KB but change the data format the EEex sync workflows write, so it is not done here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- README: hover in the feature list and the early-version note (no longer "planned"). - Editor guide: the hover row in "What you get", and what other editors need: `hover.contentFormat` for Markdown, `locale` for the server's own words (and how a locale is matched). - CONTRIBUTING: layout (src/server/hover/, data/lua52/, l10n/server/), `npm run lua-manual`, server strings under Localization, and a section on the Lua 5.2 manual data (regenerate, --check, --compare-online). - CLAUDE.md: purpose line, layout and the lua-manual command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… redefines
Found by the project review. The document's own definition already won
over the libraries for globals (`string = {}`), but not for members:
after `string.format = myFormat` or `function string.format() end`,
hovering `string.format` still showed the manual's description, which no
longer applies.
The resolver now collects, once per parsed document, the `table.field`
names the document assigns on global tables (`t.f = …`, `_G.t.f = …`,
`function t.f()`, `function t:f()`; not on locals or fields of a local
`_ENV`), and skips the manual entry for those members, including
`("x"):rep()` when `string.rep` is redefined. Other members of the same
library are still documented.
UI.MENU timings are unchanged within noise: first hover 5.0 ms (was
4.7), median 0.09–0.10 ms, worst 4.9 ms (was 4.4), five runs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by the project review. In Markdown, `!` directly before a link
makes it an image (``). No entry of the manual has text
ending in `!` before a link today, but the converter did not guard
against it. `!` is now escaped in text like the other characters
Markdown interprets.
The only change to data/lua52/manual.json is in `assert`
("assertion failed\!"), which renders the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeQL flagged the download code on this pull request (js/http-to-file-access and js/file-system-race at third_party/lua52/tarball.mts:35). The same code was already flagged in build.mts on main (alerts #2 and #4, open); moving it made the alerts count as new. Both findings were real: - the downloaded bytes were written to .cache/lua before their SHA-256 was checked, so unverified data reached the disk and was deleted only afterwards; - `existsSync` followed by `writeFileSync` raced with anything else creating or removing the file in between. Now the cache file is read directly (a missing file is ENOENT, no separate existence check), and a download is hashed in memory and written only when it matches the published SHA-256; a mismatch writes nothing. A cached file with the wrong checksum is still deleted with the same message. The source (URL, checksum, cache path, downloader) can be injected, so the new unit tests cover every path without network: download and cache, tampered download, verified cache hit, corrupt cache, and a failed download. Checked by hand: `build:wasm -- --check` and `lua-manual -- --check` pass, including with an empty .cache/lua (fresh download, byte-identical to the previously cached file). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The next step from
plan.mdafter #5: hover (textDocument/hover). Perplan.md, the help text keeps the wording and formatting of the official Lua 5.2 manual, and covers only the globals and thebit32,debug,math,stringandtablemodules.Decisions taken with the maintainer before implementation:
InitializeParams.locale, so every LSP editor gets them. No new dependency.local function f(a, b),(parameter) a,(for variable) i,(global) function G(x)). No type inference, no doc comments (those come with the JSDoc step).What a hover shows
pairs,string.format,math.pi,string; also_G.string.formatand("x"):rep())Lua 5.2 Reference Manual, §6.4 – String Manipulationprintstdout)EEex_*,Infinity_*,C:AddGold, also called asC.AddGold,EEex_Options_Option.new)EEex Functions/EE Game Lua Functions)forvariable, implicitself.menufile)io,os,require,coroutine(not opened by the engine, per IESDP)(global) io: no documentationlocal string = {}), library members the document redefines (string.format = f), names resolved through a local_ENVMarkdown or plain text, whichever the client prefers (
hover.contentFormat).Where the manual text comes from (and how that is audited)
doc/manual.htmlfrom the SHA-256-pinnedlua-5.2.4.tar.gz, the same verified tarball the embedded compiler is built from. The download and verification code is now shared (third_party/lua52/tarball.mts).npm run lua-manualwrites the committeddata/lua52/manual.json: 106 entries (§6.1: 24, §6.4: 15, §6.5: 7, §6.6: 30, §6.7: 13, §6.10: 17, module tables included). The new CI job Lua 5.2 manual data is current reruns it with--check.--compare-online, 2026-10-29). The sections and all 106 entries generated from https://www.lua.org/manual/5.2/manual.html are identical to the tarball's. The only difference is the copyright line (tarball 2011–2015, online 2011–2013; the page was last modified 2019-08-29). The tarball stays the source: it is pinned, verifiable, and the newer text.<sup>becomes Unicode superscripts (2³²,eˣ);<code>%<em>d</em></code>(instring.gsub) becomes`%`*`d`*;<em>body</em>inside a<pre>(inipairsandpairs) keeps its text without emphasis.THIRD_PARTY_NOTICES.mdgains a section with that line and the license text. It appears automatically whenever the bundle contains the data.Commits (one concern each; review them one by one)
refactor(wasm): share the verified Lua 5.2.4 tarball downloadtarball.mts;build:wasm -- --checkis still byte-identicalbuild: convert the Lua 5.2 manual's HTML subset to Markdownbuild: generate the Lua 5.2 library reference from the official manualci: check that the Lua manual data matches the official tarballnpm ci, 5 min timeout. The Lua tarball gets its own cache shared withwasm(see CI below).feat(server): record names resolved through a local _ENVScopeAnalysis.environmentFields; navigation and rename are unchangedfeat(server): index member names and declaration sitesmembers.ts,signatures.ts, a genericwalk.ts, and a sharedidentifierAtfeat(server): localize server messages from the client's localel10n/server/*.jsonbundled through JSON import attributes;check-l10nsteps 6–7; the VSIX ships onlyl10n/bundle.l10n*.json(vsce lsunchanged)feat(server): resolve hover targetsknowledge.tsandresolve.ts(rules above)feat(server): render hovers in Markdown and plain textrender.ts; 4 server strings in 15 tablesbuild(notices): credit the Lua 5.2 manual when its text is bundledfeat(server): add hoverdocs: document hoverfix(server): do not quote the manual for library members the document redefines/reviewfinding (below)fix(build): escape `!` in Markdown generated from the Lua manual/reviewfinding (below)fix(wasm): cache the Lua tarball only after verifying it, without a raceProject
/reviewfindings and what was donestring.format = f,function string.format()) still showed the manual text, unlike a redefined global!before a link would make Markdown render an image (no current entry has this)assertion failed\!, which renders the same.manual.jsonwould throw when the server loads--checked in CI, so a build that ships bad data would already have failed.tarball.mtshas no unit test (network andtar)CodeQL findings on this PR and what was done
CodeQL flagged
js/http-to-file-accessandjs/file-system-raceatthird_party/lua52/tarball.mts:35. This is the download code moved frombuild.mts, wheremainalready has the same two alerts open (#2 and #4, never triaged); moving it made them count as new. Both were real:.cache/luabefore its SHA-256 was checked;existsSyncthenwriteFileSyncwas a check-then-act race.Fixed in commit 15: the cache is read directly (
ENOENTmeans not cached), and a download is hashed in memory and written only when it matches. CodeQL now reports no open alerts for this PR. Alerts #2 and #4 refer to code that no longer exists inbuild.mts, so they should close when this merges. The similar pre-existing alerts #1 and #3 inscripts/eeex-docs/sync.mtsare out of scope here.No
vscodeimport insrc/serverorsrc/shared, no client, command or setting changes, and no new dependencies.How it was tested
Locally (Linux/WSL2, Node 24.22.1):
check-types;lint(0 warnings);test:unit(337 passing, up from 272);check-l10n(14 locales, 4 server strings). The newcheck-l10nsteps were also shown to fail on a missing table, a missing or changed key, and an unused key.lua-manual -- --check,lua-manual -- --compare-onlineandbuild:wasm -- --check(Emscripten 6.0.13) pass.package,notices -- --check, thenvsce package+vsce ls. The CI allow-list finds no unexpected file.actionlint1.7.12 passes. shellcheck is not installed locally, so therun:steps were not shell-linted.test:unitafter commit 15: 342 passing.npm test: 35 passing on both VS Code 1.91.0 and 1.144.0 (6 new hover tests). They cover:string.formattext and link;forvariable and a global function;printnote;string;.menuglobal assigned in another chunk, andstring.repinside a.menuscript.Performance (the game's
UI.MENU, 588 KB, 16,425 names; local and gitignored, nothing copied; five runs):The budget is 50 ms per request.
Size:
maindist/server/server.jsOf the server growth, the manual text is 81.4 KB and the EEex-Docs names and links 146.7 KB. Stripping the links' shared URL prefixes would save about 58 KB, but it would change the data format that the EEex sync workflows write, so it is left for a separate change.
CI:
wasmruns becausethird_party/lua52/changed. Its emsdk cache path changed (the Lua tarball moved to its own key), so this run misses that cache once and reinstalls emsdk.manualruns for the first time.CI results for the final commit, every check green, against the previous
mainand PR runs:No job is slower than its baseline beyond the one predicted cache miss.
Limitations
(global) X; cross-file navigation is a later step.s:rep(); string literals work)._ENVas globals.Checklist
npm run check-types,npm run lintandnpm run test:unitpassnpm test(integration) passes, if activation, commands, settings or the LSP wiring changedvscode.l10n.t()/package.nls.json, andnpm run check-l10npasses. Server strings use the new server tables, whichcheck-l10ncovers.CHANGELOG.mdanddocs/CHANGELOG.vsix.mdhave entries under[Unreleased](if users notice the change)🤖 Generated with Claude Code