Repository navigation
feat(server): add Lua 5.2 parser, document symbols and folding - #3
Merged
Merged
Conversation
The publish job ran on every push to main that touched VERSION. The scaffold PR (#1) reset VERSION to 0.0.0 and so started a release run on main that failed in "Verify version" (run 40704747499: CHANGELOG.md has no non-empty "## [0.0.0] - YYYY-MM-DD" section). Nothing was published, but the failure was noise, and the next version change would repeat it. publish now also requires the pushed commit to start with "chore(release): ". The prepare job opens release pull requests with a single commit and a title that are both "chore(release): vX.Y.Z", and the repository squash-merges with COMMIT_OR_PR_TITLE, so the merge commit always carries that prefix. Other VERSION changes skip the job, and a skipped job is not a failure. actionlint 1.7.12 passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stable version VERSION, package.json and package-lock.json move from 0.0.0 to 1.0.0 (set with `npm version 1.0.0 --no-git-tag-version`). Until now, with no tag, `prepare` used VERSION as a baseline and always went strictly above it, so 1.0.0 itself could never be released (the next releases would have been 1.1.0 or 1.2.0). The new pure function releaseVersion() in scripts/release/version.mts handles the first release: - no tag, stable: the committed VERSION as is (it must have an even minor, otherwise prepare fails with an actionable message); - no tag, pre-release: the next odd line, 1.0.0 -> 1.1.0; - a tag exists: nextVersion() from it, unchanged. prepare still requires at least one releasable (feat/fix/perf/revert or breaking) commit. `npm version --allow-same-version` was already passed, so keeping 1.0.0 unchanged works. Docs: version examples in README, CONTRIBUTING, both changelog headers and the bug report placeholder now use the 1.x line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every planned language feature (symbols, folding, completion, hover, navigation, rename, semantic tokens) needs a syntax tree with source positions; the embedded official compiler only reports whether a chunk compiles. This adds an original parser in src/server/syntax/ (pure: no LSP or vscode imports), with no new dependency. - lexer.ts follows lua-5.2.4/src/llex.c: ASCII names, the 22 reserved words, read_numeral (hex fractions and p exponents, malformed numbers), every 5.2 escape (\z, \x, \ddd, \ + line break), long brackets of any level, short and long comments kept apart from tokens. Offsets are document offsets, so chunks embedded in .menu files need no mapping. - ast.ts: typed node unions for the whole Lua 5.2 grammar (manual §9), each with [start, end) offsets and the offsets of closing keywords. - parser.ts: recursive descent mirroring lparser.c, with the official operator priorities, the `...`-outside-vararg and break-outside-loop checks, and the LUAI_MAXCCALLS nesting limit counted the same way as `enterlevel`. Error tolerant: it never throws, skips to the next statement after an error and keeps constructs whose closing keyword is missing, so features keep working while the user types. It publishes no diagnostics: the official compiler stays their only source. Not checked, by design: goto/label rules and code-generation limits (locals, upvalues, registers, constants). Verification against the official Lua 5.2.4 compiler (the embedded WebAssembly module): - test/unit/server/syntax/differential.test.ts: a fixed corpus of 81 accepted/rejected inputs, 4 seeds covering every statement and expression form, and 1,600 deterministic token mutations (1,401 of them rejected by the compiler); acceptance must match exactly. - Locally, 99,338 first- and second-order mutations: 0 disagreements. - Nesting limits match the compiler exactly (e.g. 198 parentheses, 200 `do` blocks, 99 nested functions). - The game's own UI.MENU (local only, never committed): 3,109 chunks, 0 parse errors, same verdict as the compiler for each, 16 ms median to extract and parse all of them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/server/syntax/scope.ts resolves every identifier of a chunk to its local declaration, or records it as a global, following the visibility rules of the Lua 5.2 manual (§3.5): - `local x = x`: the new local is visible only after the statement; - `local function f`: visible in its own body (unlike `local f = function`); - parameters and the implicit `self` of `function a:m()` in the body, `for` variables in the loop body (loop expressions are outside it); - `repeat … until cond`: cond sees the body's locals; - block scopes end at their closing keyword, shadowing resolves to the innermost declaration; only the first name of `function a.b.c()` and no table-constructor field name is a variable. Document symbols use it to tell a global assignment from an assignment to an existing local; go to definition, references and rename will use the same declarations and references later. Pure module, unit-tested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The existing .menu scanner (extractMenuLua) now also returns `blocks`:
the nested `{ … }` tree, each with its keyword (`menu`, `button`, …),
the offsets of both braces, and its `name '…'` / `name "…"` property.
Extending the one scanner keeps a single definition of the menu syntax
(strings, `--` comments and backtick blocks hide their braces), so
symbols and folding see exactly what validation sees.
LuaChunk gains `origin` (`file`, `block` or `property`) so features can
treat `` `…` `` blocks differently from `action "…"` scripts. Chunks,
problems and diagnostics are unchanged; all existing tests pass as is.
Checked on the game's own UI.MENU (local only): 144 top-level blocks,
all `menu`, all named, 2,146 blocks in total, none unclosed, and every
nested keyword is an element type (button, label, text, list > column,
slot, edit, slider, template, handle, map, movie).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
textDocument/documentSymbol for .lua and .menu files: the Outline view, breadcrumbs and "Go to Symbol in Editor". - src/server/syntax/document.ts: parseDocument() parses every Lua chunk of a document (reusing documentKind and extractMenuLua) and runs the scope analysis. - src/server/documentCache.ts: parse results keyed by URI + version, shared by the features and dropped when the document closes (.claude/rules/language-server.md › Performance). - src/server/syntax/symbols.ts (pure): functions and methods at any depth, nested under their enclosing function; locals declared by top-level statements; the first assignment to each global outside any function; named fields of table constructors. Assignments to existing locals, and locals inside blocks or functions, are left out so the outline shows definitions rather than every name. In .menu files each `menu` block is a Namespace named by its `name` property (the keyword when unnamed) holding the Lua symbols inside it; "…" scripts such as onOpen contribute functions only. - src/server/features/documentSymbols.ts: hierarchical DocumentSymbol[] when the client announces hierarchicalDocumentSymbolSupport, otherwise flat SymbolInformation[] with container names (other editors). Honors the cancellation token, never throws (logs and returns null). - Capability: documentSymbolProvider (label "IE Lua"). Tests: unit tests for symbols (including selection ⊆ range for every symbol and symbols around syntax errors) and the cache; integration tests with new original fixtures (outline.lua, OUTLINE.MENU) through vscode.executeDocumentSymbolProvider, passing on VS Code 1.91.0 and 1.143.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
textDocument/foldingRange for .lua and .menu files.
Once a server provides folding ranges, VS Code uses them instead of
indentation and of the `{`/`}` folding markers of
language-configuration/ie-menu.json, so the ranges cover everything those
did, plus Lua structure:
- Lua: function bodies, do/while/for/repeat, each if/elseif/else clause,
multi-line table constructors, parenthesized call arguments and long
strings, long comments and runs of two or more `--` lines (kind
comment);
- .menu: every `{ … }` block, `` `…` `` blocks, multi-line "…" scripts,
and the Lua constructs inside them.
A construct folds to the line before its closing keyword, which stays
visible (`end`, `until`, `}`, `)`, the next `elseif`/`else`, a closing
`]]`, backtick or quote); comments fold entirely; a construct with a
missing closer folds to its last line. One range per start line (the
outermost). No region markers: VS Code's built-in Lua
language-configuration.json defines none (checked at the 1.91.0 tag),
so recognizing one would be an invention.
src/server/features/foldingRanges.ts honors `rangeLimit` (keeps the
first ranges), omits the comment kind when the client's valueSet lacks
it, returns whole-line ranges only (fine for `lineFoldingOnly`), checks
the cancellation token and never throws. Capability:
foldingRangeProvider.
The pure logic (src/server/syntax/folding.ts) is unit-tested with LSP
line numbering; integration tests use vscode.executeFoldingRangeProvider
(present in 1.91.0, checked in extHostApiCommands.ts at that tag) on the outline fixtures and pass on VS Code
1.91.0 and 1.143.1. On the game's own UI.MENU (26,101 lines, local only):
4,510 ranges in 5 ms, after a 26 ms parse that symbols reuse.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- README: the two new features, and the "early version" note. - docs/editors/README.md: a "What you get" table with the LSP requests the server answers (diagnostics, document symbols, folding) for users of other editors, and that symbols and folding do not depend on validate.mode. - CLAUDE.md (§1 purpose, §2 layout) and CONTRIBUTING (layout): the new src/server/syntax/ folder and its differential test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s and folding Found by the project /review: the code that adapts results to the client was only exercised through VS Code, which always takes the hierarchical symbol path and accepts every folding kind. - toLspSymbols() (features/documentSymbols.ts): hierarchical DocumentSymbol[] or flat SymbolInformation[] with container names, the path that editors without hierarchicalDocumentSymbolSupport use. - toLspFoldingRanges() (features/foldingRanges.ts): rangeLimit truncation (a negative limit counts as 0) and dropping the comment kind when the client's valueSet lacks it. Both are pure and unit-tested in test/unit/server/features/; the handlers keep only document lookup, cancellation and error logging. The cache's `size` getter is now documented, and the folding integration test sorts ranges numerically before formatting them. No behavior change: 141 unit tests and 11 integration tests (VS Code 1.91.0 and 1.143.1) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found while checking the CI timings of this pull request: every "Integration tests" job, on this branch and on main since #1, logged `0 passing (0ms)` and succeeded. ci.yml calls `npx vscode-test --label` directly to pick one VS Code version, which skips npm's `pretest` script (`node esbuild.mjs --tests`), so out/test/integration/ never existed and the test glob matched nothing. The suites passed only locally, where `npm test` runs pretest. - ci.yml: a "Build extension and integration tests" step runs `npm run pretest` before vscode-test (same command as `npm test`). - .vscode-test.mjs: mocha `failZero: true` (mocha 11.8.0, used by @vscode/test-cli, applies it from mochaOpts), so a run without tests fails. Verified locally: without the build, `vscode-test --label minimum` now ends with "1 test failed." and exit code 1 (before: 0 passing, exit 0); with it, 11 passing. - .mocharc.json: `fail-zero` for the unit tests as well (mocha 12 already fails when no file matches; this covers matching files with no tests: exit 1 instead of 0, verified with an empty test file). actionlint 1.7.12 passes. The integration jobs will take a few seconds longer for the build and for actually running the 11 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
CI after the fix (921132a): all green, integration tests run for real
🤖 Generated with Claude Code |
This was referenced Oct 28, 2026
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 after syntax diagnostics (#1). Every remaining feature planned (completion, hover, go to definition, references, rename, semantic tokens, …) needs a syntax tree with source positions, and the embedded official compiler only says whether a chunk compiles. This PR adds that foundation, plus the first two features built on it:
src/server/syntax/, no new dependency, checked against the official Lua 5.2.4 compiler..luaand.menu..menublock and script.It also sets versioning to start at 1.0.0, with 1.0.0 as the first stable release, and fixes the Release workflow, which ran (and failed) on any push that touched
VERSION.Commits (one concern each; review them one by one)
ci(release): publish only when a release pull request is mergedpublishnow also requires the pushed commit to start withchore(release):. Before, any push touchingVERSIONstarted it. #1 caused failed run 40704747499 (CHANGELOG.md has no non-empty "## [0.0.0]" section; nothing was published), and this PR would have caused another. The guard holds with the repository'sCOMMIT_OR_PR_TITLEsquash setting: release PRs have exactly one commit, and its message matches the PR title.build(release): start versioning at 1.0.0 …VERSION/package.json/lock → 1.0.0 (vianpm version). New purereleaseVersion()for the case with no tag yet: stable → the committed VERSION as is (1.0.0); pre-release → 1.1.0; once a tag exists, the old logic applies unchanged. An odd committed minor is refused with an actionable message.feat(server): add an error-tolerant Lua 5.2 lexer and parserlexer.tsfollowsllex.c;parser.tsmirrorslparser.c(priorities,.../breakchecks,LUAI_MAXCCALLS). It never throws, recovers at statement boundaries, and publishes no diagnostics: the official compiler stays their only source.feat(server): add Lua scope analysisself,forvariables andrepeat … untilscoping (manual §3.5); globals by name.feat(server): report the block structure of .menu files{ … }blocks and theirname; chunks gain anorigin(file/block/property). Diagnostics are unchanged.feat(server): add document symbolsdocumentSymbolProvider.feat(server): add folding rangesrangeLimitand kinds. CapabilityfoldingRangeProvider.docs: document symbols and foldingrefactor(server): extract and unit-test the LSP conversions …/review: the flat-symbol path (used by other editors) and the folding capability handling now have unit tests.ci: build the integration tests before running them, and fail empty runs0 passing (0ms)and passed.npx vscode-test --label …skips npm'spretestbuild, so no test files existed. CI now runsnpm run pretestfirst, andfailZero/fail-zeromake any run that finds no tests fail (both verified locally: exit 1 instead of 0).Changelog entries (
CHANGELOG.mdanddocs/CHANGELOG.vsix.md) were added in the commits that make each change, as CLAUDE.md requires.How it was tested
Locally (Linux/WSL2, Node 24):
check-types,lint(0 warnings),test:unit(141 passing),check-l10n,package,notices -- --check,vsce package+vsce ls(allow-list unchanged),actionlint1.7.12,commitlinton all commits and on the title, andnpm test(11 passing on VS Code 1.91.0 and 1.143.1).Parser vs. the official Lua 5.2.4 compiler (the embedded WebAssembly module is the oracle):
test/unit/server/syntax/differential.test.tsruns a fixed corpus of 81 inputs, 4 seeds covering every statement and expression form, and 1,600 deterministic token mutations (the compiler rejects 1,401 of them, so both outcomes are exercised). Acceptance must match exactly.doblocks, 199 tables, 99 nested functions.On the game's own
UI.MENU(local only;samples/is gitignored and nothing from it was copied). It has 26,101 lines and 3,109 Lua chunks:menublocks, all named; 2,146 blocks, none unclosed, every nested keyword an element typeEverything stays under the ~50 ms event-loop budget from
.claude/rules/language-server.md, so no yielding was needed.Release dry run (scratch clone with a
feat:commit, nothing pushed):prepare --channel stablegives 1.0.0 with both changelogs promoted,[1.0.0]: …/releases/tag/v1.0.0, andverifypassing.prepare --channel pre-releasegives 1.1.0.Bundle size: server 375,361 → 401,293 bytes (+25,932, +6.9%); client unchanged (435,815 bytes); still 10 npm packages in the notices.
CI timing review (first push, against PR #1's per-job baseline): checks 25 s (19 s), CodeQL JS/TS 72 s (61 s), actions 33 s (46 s), commitlint 15 s (17 s), integration stable 43 s (45 s), integration minimum 50 s (23 s, 2.2×). The step timings showed both caches hit (npm 47 MB, VS Code 129 MB), so the extra setup seconds were network variance. The log, however, showed that no test was running at all, which commit 10 fixes. The second push's timings are in a comment below.
Known limitations (by design, documented in the code)
"…"menu scripts (runtime state).language-configuration.jsondefines no region markers (checked at the 1.91.0 tag), so recognizing a marker syntax would be an invention. This corrects an assumption in my plan.{/}markers inlanguage-configuration/ie-menu.json. The ranges cover every such block.Out of scope, found while investigating
Three Dependabot update jobs on
mainare failing and need a separate fix:No matching version found for @typescript-eslint/eslint-plugin@8.72.1 with a date before 10/25/2026. This looks like the cooldown window independabot.ymlclashing with the pinnedtypescript-eslint.@azure/msal-nodesecurity update:dependency_still_vulnerable. It's a transitive dependency of@vscode/vsce, a dev dependency that is not bundled.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 (no new strings)CHANGELOG.mdanddocs/CHANGELOG.vsix.mdhave entries under[Unreleased](if users notice the change)🤖 Generated with Claude Code