Repository navigation
feat: add quick fixes for .menu diagnostics - #13
Merged
Merged
Conversation
`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>
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
This is the next
plan.mdstep after #12: Quick fixes (textDocument/codeAction). Only JSDoc is still missing.The server now offers quick fixes for the three
.menudiagnostics whose remedy IESDP states. It also offers asource.fixAll.ieLuaaction that applies all of them, including on save.Decisions taken with the maintainer before implementation:
lua-syntax,menu-unterminated-stringormenu-unterminated-block: where the text should end, or how to repair the Lua, would be a guess.<code>problems quick fix and asource.fixAll.ieLuasource actionFixes
menu-unquoted-underscoreMy_Menu→"My_Menu"(Enclose in quotes)menu-word-too-long"…". 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`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 as10_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
sourceIE Lua) and whose code has a fix. It isisPreferred, linked to its diagnostic, and offered only if the current text still has that problem at exactly that range.savemode after later edits, and with a range past the end of a line, whichoffsetAtwould clamp.source.fixAll.ieLua: every fix in the current text, whether or not its diagnostics were published, so it also works inmanualmode. Use it with"editor.codeActionsOnSave": { "source.fixAll.ieLua": "explicit" }.FIX_ALL_KINDinsrc/shared/protocol.ts). Users put it in their settings, so it must never be renamed.context.onlyis matched by prefix, as LSP specifies:sourceandsource.fixAllincludesource.fixAll.ieLua. Withoutonly, the server returns quick fixes only.codeActionProvider: { codeActionKinds: ['quickfix', 'source.fixAll.ieLua'] }, advertised only withcodeActionLiteralSupport. Other clients could only receiveCommands, which the server does not implement.documentChanges(the rename feature'stoWorkspaceEditis reused).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.null) when the request is cancelled or the document version changes (TextDocumentsupdates documents in place, so the version is compared, not the object). Commit 4.Commits (one concern each; please review them one by one)
feat(server): compute quick fixes for misread .menu textsrc/server/codeActions/quickFixes.ts(pure) + 14 unit testsfeat(server): add quick fixes and fix-all for .menu diagnosticsFIX_ALL_KIND, 15 l10n tables, original fixtureQUICKFIX.MENU, 12 unit tests + 4 integration tests, both changelogsdocs: document quick fixesperf(server): make code action requests with many diagnostics cancellablefix(server): group fixes by code once and type the literal-support check/reviewfindings (below)docs: say that quick fixes change the compiled Lua/reviewfinding (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
/reviewfindings and what was doneenabled "My_Var"compilesMy_Var, notMy. The safety check covers the.menulexing only.supportsCodeActionLiterals(unknown)The review also checked:
vscodeimport insrc/serverorsrc/shared;engines.vscodechange, and no ID renamed;nullfor stale or cancelled requests.How it was tested
Locally (Linux/WSL2):
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 runvscode.executeCodeActionProvideronQUICKFIX.MENUafterieLua.validateDocument:source.fixAll.ieLuaapplied to an untitledie-menudocument with no published diagnostics;.luafile.package, thennotices -- --check, thenvsce package+vsce ls. The VSIX has 42 files, unchanged, with nosrc/,test/, maps ornode_modules.Corpus check on the 20 real
.menufiles on the machine (619 KB, EEex and game overrides; read in place, nothing copied or committed):_, long words added, and every backtick block ending in a non-space._runs, 1,263 long words, 98 blocks)source.fixAll_runsTimings (local; mean of 3 runs; mutated 645 KB
UI.MENU, 2,071 fixes):source.fixAll(2,071 changes, safety check)Size (both built locally from the same tree;
mainin a temporary worktree):maindist/server/server.jsdist/client/extension.jsscripts/release/vsix.mts)Limitations
.menufiles only. Lua syntax errors and unterminated strings or blocks get no fix (see the decisions above)._runs (10_0) keep their warning, with no fix.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 (the action titles are server strings, inl10n/server/, checked bycheck-l10n)CHANGELOG.mdanddocs/CHANGELOG.vsix.mdhave entries under[Unreleased](if users notice the change)source.fixAll.ieLuais called out as a new public contract)🤖 Generated with Claude Code