Skip to content

feat: add quick fixes for .menu diagnostics - #13

Merged
4Luke4 merged 6 commits into
mainfrom
feat/quick-fixes
Nov 5, 2026
Merged

4Luke4 merged 6 commits into
mainfrom
feat/quick-fixes

Conversation

@4Luke4

@4Luke4 4Luke4 commented Nov 5, 2026

Copy link
Copy Markdown
Owner

What and why

This is the next plan.md step after #12: Quick fixes (textDocument/codeAction). Only JSDoc is still missing.

The server now offers quick fixes for the three .menu diagnostics whose remedy IESDP states. It also offers a source.fixAll.ieLua action that applies all of them, including on save.

Decisions taken with the maintainer before implementation:

Question Decision
Next feature Quick fixes
Which diagnostics The 3 with an IESDP remedy. No fix for lua-syntax, menu-unterminated-string or menu-unterminated-block: where the text should end, or how to repair the Lua, would be a guess.
Backtick fix Insert a space (IESDP allows "a line break or a space"), so the line layout stays the same
Fix-all Per-code Fix all <code> problems quick fix and a source.fixAll.ieLua source action

Fixes

Code IESDP text Fix (title)
menu-unquoted-underscore "Underscores are not part of a word … Always quote names." My_Menu → "My_Menu" (Enclose in quotes)
menu-word-too-long "A longer unquoted word aborts the game. Quoted strings are not limited." The word in "…". When the word is joined to _, the whole run is quoted, because quoting the word alone leaves the rest misread.
menu-inline-lua-last-character "end every inline block with a line break or a space" `x = 1` → `x = 1 ` (Insert a space before the closing backtick)

My own decision (please check): a run of digits and _ with no letter, such as 10_0, gets no fix. IESDP's rule is about names. Quoting would turn a number into a string, and what was meant (100? 10 0?) is unknown. The diagnostic stays.

Rules

  • Quick fix: one for each diagnostic in the request that this server published (source IE Lua) and whose code has a fix. It is isPreferred, linked to its diagnostic, and offered only if the current text still has that problem at exactly that range.
    • A diagnostic from an older version of the file gets no fix, so no edit lands in the wrong place. This happens with the default save mode after later edits, and with a range past the end of a line, which offsetAt would clamp.
  • Per-code fix-all: offered with a quick fix when the file has more than one problem of that code.
  • source.fixAll.ieLua: every fix in the current text, whether or not its diagnostics were published, so it also works in manual mode. Use it with "editor.codeActionsOnSave": { "source.fixAll.ieLua": "explicit" }.
    • ⚠️ This kind string is a new public contract (FIX_ALL_KIND in src/shared/protocol.ts). Users put it in their settings, so it must never be renamed.
  • context.only is matched by prefix, as LSP specifies: source and source.fixAll include source.fixAll.ieLua. Without only, the server returns quick fixes only.
  • Capability: codeActionProvider: { codeActionKinds: ['quickfix', 'source.fixAll.ieLua'] }, advertised only with codeActionLiteralSupport. Other clients could only receive Commands, which the server does not implement.
  • Edits are versioned when the client supports documentChanges (the rename feature's toWorkspaceEdit is reused).
  • Titles are localized in the 14 VS Code display languages, like the hover labels (machine translations; review welcome).

Safety. Before any set of edits is offered, the edited text is lexed again. Its problems must be exactly the original problems that no fix touches, at their shifted offsets. Otherwise nothing is offered, and an error is logged. This is the same idea as the formatter's re-lex check.

Cancellation. Each safety check lexes the document again: 7.5 ms on a 645 KB UI.MENU.

  • A request for a whole-file selection carries every diagnostic. With 2,071 of them that is about 15 s of work, and it used to run in one synchronous turn.
  • The handler now yields to the event loop between diagnostics. It stops (null) when the request is cancelled or the document version changes (TextDocuments updates documents in place, so the version is compared, not the object). Commit 4.

Commits (one concern each; please review them one by one)

# Commit What it changes
1 feat(server): compute quick fixes for misread .menu text src/server/codeActions/quickFixes.ts (pure) + 14 unit tests
2 feat(server): add quick fixes and fix-all for .menu diagnostics Handler, wiring, FIX_ALL_KIND, 15 l10n tables, original fixture QUICKFIX.MENU, 12 unit tests + 4 integration tests, both changelogs
3 docs: document quick fixes README, editors guide, CONTRIBUTING, CLAUDE.md
4 perf(server): make code action requests with many diagnostics cancellable Yield and stop between diagnostics; look up fixes by offset (above) + 2 tests
5 fix(server): group fixes by code once and type the literal-support check Project /review findings (below)
6 docs: say that quick fixes change the compiled Lua Project /review finding (below)

Each commit type-checks, lints and passes the unit tests on its own (checked in a temporary worktree: 473 on main → 487 → 499 → 499 → 501 → 501 → 501).

Project /review findings and what was done

Finding Severity Outcome
The docs didn't say that a fix changes the Lua the game compiles: the dropped character now runs, and enabled "My_Var" compiles My_Var, not My. The safety check covers the .menu lexing only. Should fix Documented (commits 5 and 6) in the module header, the changelog and the editors guide. This is intended; validation then reports any error the misread text hid.
The per-code fix-all filtered every fix once per diagnostic (O(D·F)) Nit Fixed (commit 5): grouped once
supportsCodeActionLiterals(unknown) Nit Fixed (commit 5): typed with the capability's own type
Header table not aligned Nit Fixed (commit 5)

The review also checked:

  • no vscode import in src/server or src/shared;
  • no client, command, setting, dependency, build or engines.vscode change, and no ID renamed;
  • the capability is advertised only together with its handler;
  • the handler checks cancellation, never throws, and returns null for stale or cancelled requests.

How it was tested

Locally (Linux/WSL2):

  • Passed: check-types; lint (0 warnings); test:unit (501 passing, up from 473); check-l10n; lua-manual -- --check.
  • npm test (xvfb-run): 51 passing on both VS Code 1.91.0 and stable 1.145.0 (4 new). They run vscode.executeCodeActionProvider on QUICKFIX.MENU after ieLua.validateDocument:
    • the preferred fix and the per-code fix-all;
    • the backtick fix;
    • source.fixAll.ieLua applied to an untitled ie-menu document with no published diagnostics;
    • no IE Lua actions for a .lua file.
  • Packaging: package, then notices -- --check, then vsce package + vsce ls. The VSIX has 42 files, unchanged, with no src/, test/, maps or node_modules.
  • commitlint passes on all 6 commits and on the title.

Corpus check on the 20 real .menu files on the machine (619 KB, EEex and game overrides; read in place, nothing copied or committed):

  • The files as they are have 0 problems, so nothing is offered.
  • To exercise the fixes, a mutated copy of each file was kept in memory: every third quoted name unquoted with _, long words added, and every backtick block ending in a non-space.
Invariant (mutated corpus: 1,228 _ runs, 1,263 long words, 98 blocks) Result
Fixes refused by the safety check (each fix alone, and all together) 0 of 2,589
Fixable problems left after source.fixAll 0
Problems left other than letterless _ runs 0
Not idempotent (fixing the result again changes it) 0

Timings (local; mean of 3 runs; mutated 645 KB UI.MENU, 2,071 fixes):

Step Time
Lex 7.2 ms
Analyze (lex + fixes) 10.4 ms
One quick fix (safety check) 7.5 ms
source.fixAll (2,071 changes, safety check) 21.9 ms

Size (both built locally from the same tree; main in a temporary worktree):

Measure main This branch
dist/server/server.js 685,124 B 695,341 B (+10,217)
dist/client/extension.js 437,728 B unchanged
VSIX 325,543 B 329,500 B (+3,957)
Installed size (scripts/release/vsix.mts) 1,244,800 B 1,255,901 B (+11,101)

Limitations

  • .menu files only. Lua syntax errors and unterminated strings or blocks get no fix (see the decisions above).
  • Fixes change the compiled Lua. This is intended, and validation may then report an error the misread text hid.
  • Whole-file selections with thousands of diagnostics. Each fix is checked by re-lexing (~7.5 ms on 645 KB), so such a request does seconds of work. It is cancellable, and VS Code cancels it when the cursor moves.
  • Letterless _ runs (10_0) keep their warning, with no fix.

Checklist

  • npm run check-types, npm run lint and npm run test:unit pass
  • npm test (integration) passes, if activation, commands, settings or the LSP wiring changed
  • New logic has unit tests; new commands/settings have an integration test (no new commands or settings; code actions have integration tests)
  • User-facing strings use vscode.l10n.t() / package.nls.json, and npm run check-l10n passes (the action titles are server strings, in l10n/server/, checked by check-l10n)
  • CHANGELOG.md and docs/CHANGELOG.vsix.md have entries under [Unreleased] (if users notice the change)
  • No setting key or command ID was renamed (breaking change), or it is called out above (no rename; the new code action kind source.fixAll.ieLua is called out as a new public contract)

🤖 Generated with Claude Code

4Luke4 and others added 6 commits November 5, 2026 11:13
`codeActions/quickFixes.ts` (pure) computes the fixes for the three .menu
diagnostics whose remedy IESDP states (MENU file format):

- `menu-unquoted-underscore`: the run in `"…"` ("Always quote names"). A
  run with no letter (`10_0`) is not a name and gets no fix: quoting would
  turn a number into a string, and what was meant is unknown.
- `menu-word-too-long`: the word in `"…"` ("Quoted strings are not
  limited"); the whole run when the word is joined to `_`, since quoting
  the word alone leaves the rest misread.
- `menu-inline-lua-last-character`: a space before the closing backtick
  ("end every inline block with a line break or a space").

No fix is offered for `lua-syntax`, `menu-unterminated-string` or
`menu-unterminated-block`, as where the text should end, or how to repair
Lua, would be a guess.

Changes of several fixes are combined in document order, each distinct
change once, overlapping ones dropped (the wider kept). Before changes are
offered, the edited text is lexed again: its problems must be exactly the
original problems no fix touches, at their shifted offsets, or nothing is
offered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`textDocument/codeAction` for .menu documents, from the fixes of
`codeActions/quickFixes.ts`:

- A preferred quick fix for each diagnostic of the request that this server
  published, whose code has a fix and whose problem is still in the current
  text at exactly that range. A diagnostic of an older version of the file
  (published on save, before later edits) gets none, rather than an edit in
  the wrong place.
- With it, "Fix all <code> problems" when the file has several problems of
  that code.
- `source.fixAll.ieLua` (`FIX_ALL_KIND` in src/shared/protocol.ts) with
  every fix of the current text, so it works from
  `editor.codeActionsOnSave` and in `manual` validation mode. The kind is a
  public contract: users put it in their settings.

`context.only` is honored by prefix, as LSP specifies; without it, only
quick fixes are returned. Edits are versioned when the client supports
`documentChanges` (`toWorkspaceEdit` of the rename feature). Changes the
safety check refuses are logged as errors and not offered.

The capability (`codeActionKinds: quickfix, source.fixAll.ieLua`) is
advertised only to clients with `codeActionLiteralSupport`: the others could
only receive commands, which the server does not implement.

The titles are localized in the 14 VS Code display languages (machine
translations, like the hover labels). Original fixture QUICKFIX.MENU;
4 integration tests, 12 unit tests; both changelogs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README (features and the early-version note), the editors guide
(capability table, which diagnostics are fixed and how to ask for
`source.fixAll.ieLua` on save), CONTRIBUTING (module table) and CLAUDE.md
(purpose and layout) describe the quick fixes for .menu files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…able

The safety check of each quick fix lexes the document again (8.5 ms for a
645 KB UI.MENU). A request for a whole-file selection carries every
diagnostic of the file, and ran all checks in one synchronous turn: about
17 s for 2,071 diagnostics, which could not be cancelled.

- `codeActions` awaits a `pause` before each diagnostic after the first;
  the handler's pause yields to the event loop (`setImmediate`) and stops
  when the request is cancelled or the document changed version
  (`TextDocuments` updates documents in place, so the version is compared,
  not the object). A stopped request answers `null`.
- Diagnostics are matched to fixes through a map keyed by code and offsets,
  instead of a scan of every fix per diagnostic. A range that is not a range
  of the current text (past the end of a line, which `offsetAt` clamps)
  matches nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Findings of the project review:

- The "fix all <code>" action filtered every fix of the document once per
  diagnostic of the request (O(diagnostics x fixes)); the fixes are now
  grouped by code once.
- `supportsCodeActionLiterals` takes the client capability's own type
  instead of `unknown`.
- The header of `codeActions/quickFixes.ts` says that the fixes change the
  compiled Lua (the dropped character runs, a quoted value is compiled
  whole), and that the safety check covers the .menu lexing only. Its table
  is aligned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The quick fixes for `.menu` files change what the game compiles, which is
the point of them. The character the game dropped before a closing
backtick now runs, and a quoted Lua property value is compiled whole, so
validation may then report an error the misread text hid. The changelog
and the editors guide say so (review finding).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@4Luke4
4Luke4 merged commit e033d9c into main Nov 5, 2026
@4Luke4
4Luke4 deleted the feat/quick-fixes branch November 5, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant