Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ the extension live in [`docs/CHANGELOG.vsix.md`](docs/CHANGELOG.vsix.md).
syntax diagnostics from the official Lua 5.2.4 compiler, built to WebAssembly from the
checksum-verified lua.org tarball (`third_party/lua52/`, reproducible build checked in CI).
- `.menu` support: new `ie-menu` language (case-insensitive `.menu` extension), TextMate grammar
with embedded Lua highlighting, and validation of `` `…` `` blocks, `action*`/`onOpen`/`onClose`
scripts, `enabled "…"` and `<property> lua "…"` expressions.
that highlights the engine's keywords and embeds Lua where validation finds it, and validation of the Lua the engine compiles, found with a lexer
that follows the engine's (per [IESDP](https://gibberlings3.github.io/iesdp/file_formats/ie_formats/menu_v1.htm)):
`` `…` `` blocks; `onOpen`, `onClose` and `action*` scripts; and the expressions of `enabled`,
`actionDrag`, `table`, `seperator`, `useOverlayTint`, `bitmap res` and every `lua` value. A value
can be `"…"`, `'…'` or an unquoted word that is not a keyword, anywhere on a line. Each is
compiled in the shape the engine compiles it: property code as the body of
`function f () … end` (so `...` and a trailing `--` comment are errors), expressions as its
`return` value, and `` `…` `` blocks without their last character, which the engine drops.
`slotinfo`, `spellInfo` and `memorizedSpellInfo` strings are checked in every expression and
statement the engine generates from them (`T.item.icon`, `Infinity_SwapSlot(T.id)`, …).
- `.menu` diagnostics for text the engine misreads (codes are stable): `menu-unterminated-string`
for `"` and `'` strings, `menu-unterminated-block`, and the new `menu-word-too-long` (error: an
unquoted word of 64 or more characters aborts the game), `menu-inline-lua-last-character`
(warning: the character before a closing backtick is dropped) and `menu-unquoted-underscore`
(warning: unquoted `My_Menu` is read as `My` and `Menu`).
- Settings `ieLua.validate.mode` (`manual`, `save` (default), `type`, `saveAndType`) and
`ieLua.validate.debounce` (default 300 ms).
- Command **IE Lua: Validate Current File** (`ieLua.validateDocument`).
Expand Down Expand Up @@ -48,6 +61,14 @@ the extension live in [`docs/CHANGELOG.vsix.md`](docs/CHANGELOG.vsix.md).
that are not Lua names or are reserved words, and any rename that would change what a name
refers to (checked by re-analyzing the renamed text). Edits are versioned when the client
supports `documentChanges`.
- Workspace symbols (`workspace/symbol`; *Go to Symbol in Workspace*): the outline symbols of every
`.lua` and `.menu` file (any letter case) in the `file:` workspace folders, and of every open
document, whose unsaved text wins over the file. The query matches loosely (its characters in
order, case-insensitively), as LSP recommends. Files are indexed in the background, one per
event-loop turn, and kept current through watched-file events (`**/*.[lL][uU][aA]`,
`**/*.[mM][eE][nN][uU]`, and creates and deletes of folders), workspace folder changes and
document closes. `files.exclude` is honored as VS Code's explorer applies it, with an original
matcher checked against VS Code's own; changing it rescans.
- Error-tolerant Lua 5.2 parser and scope analysis (`src/server/syntax/`), checked against the
official compiler by a differential test; it publishes no diagnostics of its own.
- Localization of the manifest and UI strings into all 14 VS Code display languages
Expand All @@ -60,6 +81,9 @@ the extension live in [`docs/CHANGELOG.vsix.md`](docs/CHANGELOG.vsix.md).

### Changed

- The extension also activates in workspaces that contain `.lua` or `.menu` files, in any letter
case (`workspaceContains:**/*.[lL][uU][aA]`, `workspaceContains:**/*.[mM][eE][nN][uU]`), so
*Go to Symbol in Workspace* works before any file is opened.
- Minimum VS Code version is 1.91.0 (required by `vscode-languageclient` 10 and later).
- Versioning starts at 1.0.0: when no release exists yet, the Release workflow ships the
committed `VERSION` as the first stable release (a pre-release before it would be 1.1.0).
Expand Down
11 changes: 9 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|---|---|
| Name | `IE Lua Language Server` |
| Publisher | `infinity-engine-tools` |
| Purpose | Lua 5.2 language support (diagnostics, document symbols, folding, and same-file definition, references and rename now; more LSP features planned) for Infinity Engine EE `.lua` files and the Lua embedded in `.menu` files, usable from VS Code and other LSP editors |
| Purpose | Lua 5.2 language support (diagnostics, document and workspace symbols, folding, and same-file definition, references and rename now; more LSP features planned) for Infinity Engine EE `.lua` files and the Lua embedded in `.menu` files, usable from VS Code and other LSP editors |
| Language | TypeScript (strict) |
| Bundler | esbuild (two bundles: client + language server) |
| Minimum VS Code | `^1.91.0` (see `engines.vscode` in `package.json`; required by `vscode-languageclient` ≥ 10) |
Expand All @@ -33,7 +33,8 @@
│ │ ├── server.ts # Connection, capabilities, handlers
│ │ ├── features/ # completion.ts, diagnostics.ts, hover.ts, ...
│ │ ├── syntax/ # Lua 5.2 lexer, parser, scopes, symbols, folding (pure, no LSP imports)
│ │ └── validation/ # Pure analysis logic (no LSP imports) — unit-tested directly
│ │ ├── validation/ # Pure analysis logic (no LSP imports) — unit-tested directly
│ │ └── workspace/ # Workspace index, files.exclude glob matching (fs injected; no LSP)
│ └── shared/ # Types/constants used by BOTH sides — no vscode imports
├── test/
│ ├── unit/ # Pure logic, runs in plain Node (no VS Code)
Expand Down Expand Up @@ -131,6 +132,12 @@ esbuild does **not** type-check. Always run `npm run check-types` — a green bu
- Only advertise capabilities that are actually implemented.
- Debug the server with `--inspect=6009` via the `debug` server options.
- Full details: `.claude/rules/language-server.md`.
- **Engine facts come from IESDP** (checked against the 2.6.6.0 and 2.7.3.0 executables), never from guesses:
[MENU format](https://gibberlings3.github.io/iesdp/file_formats/ie_formats/menu_v1.htm) (lexer, grammar,
which properties are Lua and the exact text compiled for them: see `src/server/validation/menu*.ts`) and
[Engine Lua globals](https://gibberlings3.github.io/iesdp/file_formats/ie_formats/lua_globals.htm). The engine's
Lua state opens only `_G`, `table`, `string`, `bit32`, `math` and `debug` and replaces `print`; `io`, `os` and
`package` (hence `require`) exist only as test-automation stubs. Hover/completion must not offer them.

---

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ server (port 6009).
| `src/server/` | Language server (separate Node process; no `vscode` import) |
| `src/server/validation/` | Pure validation logic, unit-tested without LSP or VS Code |
| `src/server/syntax/` | Error-tolerant Lua 5.2 parser, scope analysis, document symbols and folding (pure; checked against the official compiler by `test/unit/server/syntax/differential.test.ts`) |
| `src/server/workspace/` | Index of the workspace's Lua and `.menu` files, and `files.exclude` matching as VS Code applies it (file system injected, unit-tested with an in-memory one) |
| `src/shared/` | Types and constants used by both sides |
| `third_party/lua52/` | Reproducible build of the official Lua 5.2.4 compiler to WebAssembly |
| `data/eeex/` | Generated EEex documentation index (names and links) |
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ Lua language support for the **Infinity Engine Enhanced Edition** games and the

> [!NOTE]
> This is an early version. It currently provides **syntax diagnostics**, **document symbols**,
> **folding**, **go to definition**, **find references** and **rename** within a file; completion,
> hover, workspace-wide navigation, formatting and more are planned.
> **workspace symbols**, **folding**, and **go to definition**, **find references** and **rename**
> within a file; completion, hover, cross-file navigation, formatting and more are planned.

## Features

- **Syntax errors from the official Lua 5.2 compiler.** The real Lua 5.2.4 front end, built to
WebAssembly, checks your code — nothing to install, and no code is ever run.
- **`.menu` files understood.** Lua inside `` `…` `` blocks, `action`/`onOpen`/`onClose` scripts,
`enabled "…"` and `<property> lua "…"` expressions is checked, and errors point to the right line
of the `.menu` file. Upper-case names like `UI.MENU` are recognized, with Lua highlighting.
- **`.menu` files understood as the game reads them.** All the Lua the game compiles is checked,
in the exact form it compiles it: `` `…` `` blocks, `onOpen`/`onClose`/`action…` scripts, and
`enabled`, `table`, `lua "…"` and other expressions, in `"…"` or `'…'`, plus the Lua the game
generates from `slotinfo` and `spellInfo`. Errors point to the right line of the `.menu` file,
and warnings flag text the game reads differently than it looks, such as `My_Menu` unquoted.
Upper-case names like `UI.MENU` are recognized, with Lua highlighting. The rules come from the
[IESDP description of the format](https://gibberlings3.github.io/iesdp/file_formats/ie_formats/menu_v1.htm).
- **You decide when files are checked:** on save (default), while typing, both, or only on request.
- **Outline and breadcrumbs.** Functions, methods, top-level variables and table fields of Lua files,
and each menu of a `.menu` file by its `name`, in the Outline view, the breadcrumbs and
**Go to Symbol in Editor**. Works while the file still has syntax errors.
- **Go to Symbol in Workspace** across every Lua and `.menu` file of your workspace, including files
you haven't opened; files hidden with *Files: Exclude* are left out.
- **Folding that follows the code:** functions, loops, each `if`/`elseif`/`else` branch, tables,
comments, and every `{ … }` block and Lua script of a `.menu` file.
- **Go to Definition, Find All References and Rename Symbol** for variables within a file. Locals
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.vsix.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ versions with an **even** middle number (for example 1.**2**.0) are stable relea
with the official Lua 5.2 compiler, and errors appear in the Problems panel.
- **`.menu` files are recognized**, including upper-case names such as `UI.MENU`, with
Lua highlighting inside them.
- **Warnings for `.menu` text the game reads differently than it looks**: an underscore in
unquoted text (`My_Menu` is read as two words), a Lua block whose last character the game
drops, and unquoted words long enough to make the game abort.
- **Choose when files are checked** with the *IE Lua › Validate: Mode* setting: on save
(the default), while typing, both, or only on request.
- **Check a file on request** with the **IE Lua: Validate Current File** command.
Expand All @@ -27,6 +30,9 @@ versions with an **even** middle number (for example 1.**2**.0) are stable relea
- **Find All References** lists every use of a variable in the same file.
- **Rename Symbol** renames a variable everywhere in the file. It refuses, and tells you why,
when the rename could break your code — for example when the new name is already used nearby.
- **Go to Symbol in Workspace** (Ctrl+T) finds functions, variables and menus in every Lua and
`.menu` file of your workspace, even files you haven't opened. Files hidden with
*Files: Exclude* are left out.
- **Available in 14 languages**, following your VS Code display language.
- **Works in other editors too**: setup guides for Sublime Text, Neovim, Emacs, JetBrains
IDEs, Helix, Zed, Kate, Notepad++ and Geany are on the project page.
13 changes: 12 additions & 1 deletion docs/editors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,23 @@ node /path/to/server.js --stdio

| Feature | LSP request | Notes |
| --- | --- | --- |
| Syntax errors | `textDocument/publishDiagnostics` | When `validate.mode` says so (see above). |
| Syntax errors | `textDocument/publishDiagnostics` | When `validate.mode` says so (see above). In `.menu` files, also warnings for text the game misreads. |
| Document symbols (outline) | `textDocument/documentSymbol` | Nested when the editor supports it, otherwise a flat list with container names. |
| Folding | `textDocument/foldingRange` | Whole lines; the closing line of each construct stays visible. |
| Go to definition | `textDocument/definition` | The declaration of a local, or every assignment to a global, in the same file. |
| Find references | `textDocument/references` | Every use of a local or global in the same file. |
| Rename | `textDocument/prepareRename`, `textDocument/rename` | Same file only; refused, with the reason as the error message, when the rename could change what the code does. |
| Workspace symbols | `workspace/symbol` | Every `*.lua` and `*.menu` file under the workspace folders, plus open files. See below. |

Workspace symbols need an editor that sends **workspace folders** when it starts the server;
otherwise only open files are searched. Files changed outside the editor are picked up when the
editor supports **dynamic registration of watched files** (`workspace/didChangeWatchedFiles`);
otherwise they are picked up when the server restarts or the file is opened and closed. Files are
skipped as VS Code's `files.exclude` setting says, which the server reads with
`workspace/configuration` (section `files.exclude`). If your editor passes server *settings*
through `workspace/configuration` (your guide says whether it does), you can add one next to
`ieLua`, for example `{ "files": { "exclude": { "**/backup": true } } }`.
Only folders on the local disk are scanned.

Symbols, folding and navigation always reflect the current text, whatever `validate.mode` is.
Navigation works on variables: table fields (`t.x`) and `goto` labels are not followed, and in a
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"l10n": "./l10n",
"main": "./dist/client/extension.js",
"activationEvents": [
"onLanguage:lua"
"onLanguage:lua",
"workspaceContains:**/*.[lL][uU][aA]",
"workspaceContains:**/*.[mM][eE][nN][uU]"
],
"contributes": {
"languages": [
Expand Down
15 changes: 11 additions & 4 deletions src/server/features/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export interface DiagnosticsDeps {
* | `type` | ✓ | | ✓ |
* | `saveAndType` | ✓ | ✓ | ✓ |
*/
export function register(connection: Connection, documents: TextDocuments<TextDocument>, deps: DiagnosticsDeps): void {
export interface DiagnosticsFeature {
/** Handles `workspace/didChangeConfiguration` (the server owns the single handler). */
configurationChanged(settings: unknown): void;
}

export function register(connection: Connection, documents: TextDocuments<TextDocument>, deps: DiagnosticsDeps): DiagnosticsFeature {
const debouncer = new Debouncer<string>(deps.timers);
/** Document version whose diagnostics were last published, per URI. */
const published = new Map<string, number>();
Expand All @@ -37,7 +42,7 @@ export function register(connection: Connection, documents: TextDocuments<TextDo
}
const diagnostics: Diagnostic[] = validateText(document.getText(), documentKind(uri, document.languageId), lua).map((problem) => ({
range: { start: document.positionAt(problem.start), end: document.positionAt(problem.end) },
severity: DiagnosticSeverity.Error,
severity: problem.severity === 'warning' ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error,
source: DIAGNOSTIC_SOURCE,
code: problem.code,
message: problem.message,
Expand Down Expand Up @@ -100,7 +105,7 @@ export function register(connection: Connection, documents: TextDocuments<TextDo
}
});

connection.onDidChangeConfiguration(({ settings }) => {
const configurationChanged = (settings: unknown): void => {
deps.settings.changed(settings);
// A switch to a `type` mode should take effect without waiting for the next edit.
for (const document of documents.all()) {
Expand All @@ -116,9 +121,11 @@ export function register(connection: Connection, documents: TextDocuments<TextDo
})
.catch(report(uri));
}
});
};

connection.onShutdown(() => {
debouncer.dispose();
});

return { configurationChanged };
}
6 changes: 6 additions & 0 deletions src/server/features/documentSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export function toLspSymbols(symbols: readonly OutlineSymbol[], options: SymbolC
});
return symbols.map(convert);
}
return flatSymbols(symbols, options);
}

/** Flat `SymbolInformation[]` in document order, each with the name of its parent as container. */
export function flatSymbols(symbols: readonly OutlineSymbol[], options: Omit<SymbolConversion, 'hierarchical'>): SymbolInformation[] {
const range = (start: number, end: number) => ({ start: options.positionAt(start), end: options.positionAt(end) });
const flat: SymbolInformation[] = [];
const flatten = (symbol: OutlineSymbol, container: string | undefined): void => {
flat.push({
Expand Down
Loading
Loading