# VS Code extension

An extension (`packages/vscode`) for writing `.lim` scenarios in VS Code, by hand or with AI.
It also works in editors that can load the same extensions as VS Code, such as Cursor.

## Installing

1. Search for "Liminalia" in the VS Code Extensions view and install it ([VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=liminalia.liminalia))
2. Open the folder that contains `liminalia.json`, and open a `.lim` file

To install from a .vsix, download `liminalia-<version>.vsix` from the [releases page](https://github.com/skyt-a/liminalia-releases/releases/latest) (each Studio release includes it),
choose "Extensions: Install from VSIX…" in VS Code's Command Palette, and select that .vsix.
To build it yourself, run `npm run -w @liminalia/vscode package` to make `packages/vscode/liminalia-<version>.vsix` (see “Building” below). To reinstall, follow the same steps; the new version overwrites the old one.

## What it does

- **Highlighting**: labels `# name`, commands `@name key=value`, comments `//`, dialogue speakers `Name「…」` and `Name "…"`, inline markup
  `{r 漢字|かんじ}` (ruby, small reading aids above characters) `{br}` `{= expression}` `{b …}` `{@command …}`, choice lines `- text -> target key=value`, `(expression)` values, strings, times, colors, and fixed line IDs `#line:…` at the end of a line (dimmed like comments)
- **Checks**: shows the same check results as `lim check` while you write. Open files are checked with their unsaved contents, and other files with their contents
  on disk. Findings in `cast.json`, `liminalia.json` and translation files (`lang/<language>.json`) are shown in those files too
- **Completion**
  - Command names after `@` (with summaries, including `@define` in that file and in files loaded with `@use`)
  - Command parameter names (`key=`) and values for their types (allowed values, `true` / `false`, characters, sprite sets, variants, positions, asset files)
  - `#label`, files and `file#label` for jump targets (`@jump` `@call`, after `->` in choices, parameters of the jump target type)
  - Speaker names at the start of a line (`speakers` in `cast.json`; the bracket is inserted too, or the quotation-mark form `Name "…"` in a project whose source language is English, where the first entry of `languages` is `en`)
  - Inline markup after `{` in text
  - In expressions (after `@if` `@elif` `@while` `@set` `@let` `@return`, in a parameter's `(…)`, and in `{= …}` in text), variables (those used in scripts, `variables` in `liminalia.json`,
    and `system.…`, whose values the engine sets) and expression functions (with their signatures). Inventory item names (`items` in `liminalia.json`) inside `item("…")`, and jump targets inside `visits("…")` `read("…")`
- **Hovers**: for a command name, the summary, an example and the parameter table; for `key=` and unnamed parameters, that parameter's description.
  In expressions, a function's signature and description, a variable's initial value and how many places write and read it, the name and description of the item in `item("…")`, and where the jump target in `visits("…")` is
- **Go to Definition**: jump targets (`#label`, `file`, `file#label`), files in `@use`, and calls to macros defined with `@define`
  (including those in files loaded with `@use`). Jump targets are found and resolved the same way as Studio's "Go to Jump Target" (⌘-click, F12) (`goto.ts` in `@liminalia/lang`)
- **Outline**: labels and `@define`
- **Find references** (⇧F12, "Find All References"): every place that uses the scene (label), script file, macro (`@define`), variable, character, speaker or asset at the cursor.
  Jump targets are resolved the same way as in Go to Definition. `{@chara …}` `{= …}` `{img …}` in text are included too
- **Workspace symbols** (⌘T): the scenes and `@define` in all of the project's scripts (for a project directly in a workspace folder, even before you open a .lim)
- **Completion and hovers for settings**: applies JSON Schemas (`packages/project/schemas`, made from the types) to `liminalia.json`, `cast.json` and translation files (`lang/*.json`), for completing item names, descriptions,
  and squiggles under unknown items. Translation files are only checked when they have `language` and `lines` (the shape `lim i18n` and Studio write)
  (`schemas/lang-file.schema.json`, so that other projects' `lang/*.json` get no squiggles; writing `"$schema"` applies it even before there are `lines`)
- **Folding**: from the parser. Scenes (from a label to just before the next label; trailing blank lines and comments go with the next scene), `@if` (each `@elif` `@else` branch separately),
  `@while`, `@with`, `@choice`, `@define`, `@script`, commands with a body (`@html`, `@staff-roll` without `file=`), and runs of `//` lines
- Toggling `//` comments, and auto-closing brackets `「」『』（）""{}`
- **Formatting** ("Format Document", ⇧⌥F): tidies command lines the same way as `lim fmt` (`formatLim` in `@liminalia/lang`). The text isn't changed.
  If there's a syntax error, it doesn't format and shows why. This extension is set as the default formatter for `.lim`
- **Quick Fix** (the light bulb, ⌘.): applies diagnostics that come with a suggested fix (`DiagnosticFix`: replacing a misspelled name, deleting an unneeded line and so on).
  Before applying, it checks that the line is still the same (`applyFix` in `@liminalia/lang`; the same as "Fix" in Studio)
- **Rename** (F2): rewrites the name at the cursor and every place that uses it. The rewriting is the same as renaming in Studio and `lim rename`
  (`@liminalia/studio/label-rename`, `label-follow`, `name-rename`, `asset-rename`)
  - Scenes: on the name in a label line, or on a jump target that points to a label (`#label`, the label part of `file#label`, choices, parameters of the jump target type).
    It updates references in other files and `entry`, `afterLoad` and the extras' jump targets in `liminalia.json`, moves translation keys (`lang/<language>.json`), locked voice numbers (`voice-lock.json`),
    review comments (`reviews/`), flowchart card positions and jump targets inside project data whose shape a plugin declared over to the new name, and renames the baseline images of `lim regress`
  - Script files: on the file part of a jump target, or on a file in `@use`. It rewrites jump targets, `liminalia.json`, translation and `voice-lock.json` keys, review comments
    and Studio's notes (bookmarks and so on), and renames the .lim, its change history folder (`.liminalia/history/`) and the baseline images
  - Macros: on the name in `@define`, the command name of a call, or the macro name in `@with`. It rewrites `@define`, the calls (including `{@…}` in text) and the keys of `commandDefaults` in `liminalia.json`
  - Variables: on `game.…` `system.…` `temp.…` in expressions, `@set` and `{= …}`. It rewrites scripts, initial values and conditions (`"if"`) in `liminalia.json`, and breakpoint conditions
  - Characters: on a parameter of the character type (`@chara Yuika …`, including `{@chara …}` in text). It rewrites scripts, keys in `cast.json`, face crops and notes, and who voices the system voices
  - Speakers: on the name at the start of a dialogue line. It rewrites dialogue lines, `speakers` and `speaker` in `cast.json`, speaker names in translations, and keys and speakers in `voice-lock.json`
  - Assets: on the value of a parameter of an asset type, or in `{img …}` (the new name is a path inside the folder of the same kind, and the extension doesn't change). It rewrites scripts (including asset parameters of macros and `@with`, and commands in text),
    commands in text and `{img …}` in translations, sprite images in `cast.json`, assets in `ui` `extra` `items` of `liminalia.json`, and `url()` and `@import` in the project's CSS, and renames the asset file.
    Places it can't rewrite (text passed to expressions, data, translations, templates, plugins and so on) are listed in a warning (the same as `lim rename … asset`; up to 10 places, with all of them in the Liminalia output)
  - For lines whose text was rewritten (`{= variable}`, `{@chara …}`, `{@macro}`, `{img …}`), translation keys and `voice-lock.json` keys are moved to the new key of the same line
- **Script tests**: lists the script tests in the workspace (`tests/*.limtest`) in VS Code's Testing view (by file, with each `# name` line as a test.
  They're listed again when you edit them, and unreadable lines show as an error on the file). Running them runs `lim test --json` for each project (`lim` is found the same way as `lim studio` for "Play from Here" below),
  and shows whether each test passed, and the lines that didn't match and why, on the test and on that line. You can also run them from the start of a `# name` line in the editor. `.limtest` files are highlighted too (`syntaxes/limtest.tmLanguage.json`).
  Scripts and tests being edited are saved before running. In an untrusted workspace, the `lim` inside the project doesn't run (`src/testing.ts`, `src/extension-tests.ts`)
- **Play from Here** (right-click, ⌘⌥P / Ctrl+Alt+P): like "Play from Here" in Studio, opens a player in the browser that starts from the state right before the cursor line runs (the background, sprites, BGM and variables set
  in earlier scenes and other files). The save is put together the same way as in Studio (`findPlayStart` in `@liminalia/studio/play-from`):
  for a line the current route doesn't pass through, it looks for a route that does, and if there's none, it starts from the state of an earlier line and says so. For lines it can't start from, such as inside a macro (`@define`),
  it starts at the beginning of that scene with variables at their initial values and fast-forwards to the cursor line's page (`?start=file#label&skip=N`).
  It uses the dev server of a Studio that has the project open (the Studio app or `lim studio`; `.liminalia/studio-server.json` in the project).
  If there's none, you choose "Open in the Studio app" or "Start lim studio", and it waits for it to start (`src/studio-launch.ts`; `npx` isn't used, so that nothing else is fetched from npm).
  The Studio app is looked for in the `liminalia.studioApp` setting, or if that's empty, in `/Applications` and `~/Applications` on Mac and in `%LOCALAPPDATA%\Programs` and `Program Files` on Windows, and it's opened with the project folder.
  For lim, the `liminalia.lim` setting (scripts such as `lim.mjs` run with Node: `liminalia.node`, or if that's empty, the one bundled with VS Code), or if that's empty, `@liminalia/cli` in the project's `node_modules`,
  is run in a terminal without going through a shell. If neither is found, it tells you to set `liminalia.lim`.
  The state at each line (where play is) comes from the dev server's `GET /sweep` (and `GET /sweep/reach`); when there's no Studio or it doesn't respond, the same thing (`@liminalia/studio/sweep`) is built inside the language server
  (plugin commands run only if they could be loaded inside the language server). The save it makes is handed to the dev server (`POST /play-from`), and from that page the browser moves to `/?play=1&from=<id>&start=<scene>`.
  With an older Studio app that can't hold saves, it opens with the same fast-forward as before
- UI text (command names, Quick Fix, refusals) follows VS Code's display language, Japanese or English (`package.nls.json`, `package.nls.ja.json`).
  Command descriptions in completion and hovers are shown in the same language too (the English comes from `summaryEn` and `docEn` in command definitions; plugin commands with no English are shown in Japanese)

Command specs are gathered from the built-in commands, the standard commands (`@liminalia/std`) and the commands of the plugins in `plugins` of the project.
Plugins are often written in TypeScript as is, so if one can't be loaded inside the extension, it's loaded again in a separate process
(using `tsx` if it can be found from the project. By default, the Node.js bundled with VS Code is used, and you can change it with the `liminalia.node` setting). If it still can't be loaded, the reason is shown in
"Liminalia" in the Output panel, and findings about unknown commands become warnings. In untrusted folders and for projects outside the workspace folders (a .lim opened outside the workspace), plugin code isn't run.
In an untrusted workspace, Play from Here doesn't run the `lim` inside the project either (in `node_modules`, or a setting that points inside the project), and the `lim studio` it starts
doesn't load plugins (`LIMINALIA_RESTRICTED=1`). The `liminalia.lim`, `liminalia.node` and `liminalia.studioApp` settings don't use workspace values until you trust the workspace
(["Opening in restricted mode" in plugins.md](plugins.md#opening-in-restricted-mode)).

The extension reloads when you change the settings, characters or plugins. If it doesn't reload properly, run
"Liminalia: Restart Language Server" from the Command Palette.

## Building

```bash
npm install
npm run -w @liminalia/vscode build     # bundle into packages/vscode/dist/ (esbuild)
npm run -w @liminalia/vscode package   # build, then make a .vsix (@vscode/vsce)
```

- The extension side (`src/extension.ts`) becomes `dist/extension.cjs`, and the language server (`src/server.ts`) becomes `dist/server.mjs`.
  `@liminalia/lang`, the runtime (`@liminalia/runtime`) and the standard commands are bundled into the language server, so the .vsix works without the engine's repository
- The logic behind completion, hovers, Go to Definition and checks is in `src/features.ts` and `src/model.ts`, and can be tested without VS Code
  (parsing a partly written line and resolving jump targets use `line-syntax.ts` and `goto.ts` in `@liminalia/lang`, shared with Studio)
  (`packages/vscode/test/`; they run with `npx vitest run` at the root of the repository)
- To try it during development, you can also open `packages/vscode` in VS Code and start the Extension Development Host from "Run and Debug"
  (run build first)

## Publishing to the Marketplace and Open VSX

The .vsix that `package` makes is ready to publish (the icon `resources/icon.png`, UI text in Japanese and English, the repository, categories and keywords).
The extension ID is `liminalia.liminalia` (the publisher is `liminalia`, and the name in the distributed package.json is `liminalia`).

- License: `license` in `packages/vscode/package.json` is `SEE LICENSE IN LICENSE` (the same as the npm packages), and `scripts/package.ts` puts the repository's LICENSE (the terms of use) in the .vsix.
  The copyright notices and license terms of the bundled dependencies (vscode-languageclient and others) are collected by `scripts/build.ts` from esbuild's metafile into `THIRD-PARTY-NOTICES.txt`, which goes in too
  (`scripts/third-party-notices.ts`; the build stops if a dependency has no license file)
- Repository: `repository` and `bugs` point to the public repository `skyt-a/liminalia-sdk` (copied with `scripts/public-mirror.mjs`)
- Publisher: the Marketplace publisher `liminalia` and the Open VSX namespace `liminalia` were created on 2026-11-22
  (verification of the Open VSX namespace's ownership is requested in https://github.com/EclipseFdn/open-vsx.org/issues/16104)

`.github/workflows/publish-vscode.yml` does the publishing. When you check and publish the draft Release that `release.yml` made, it publishes that Release's
`liminalia-<version>.vsix` (as with npm, the same version can't be published twice, so nothing is published while it's a draft). It skips a store without a token and versions that already exist,
and doesn't publish versions with a `-` (pre-releases). If it fails partway, run it manually with the version to publish the rest.

Current state (2026-11-22):

- Open VSX (Cursor, VSCodium and others): the `OVSX_PAT` secret is set (a token limited to the `liminalia` namespace, Publishing only).
  Publishing the Release publishes it. To replace the token, create one under Access Tokens in the settings at https://open-vsx.org and set it again with `gh secret set OVSX_PAT`
- VS Code Marketplace: there's no `VSCE_PAT`. The Azure DevOps organization that issues Marketplace tokens can't be created without an Azure subscription (a billing setup).
  For each version, upload the Release's `liminalia-<version>.vsix` by hand from "New extension" → "Visual Studio Code" at
  https://marketplace.visualstudio.com/manage/publishers/liminalia (it's published after a few minutes of verification). With Azure set up and `VSCE_PAT` added, publishing the Release would publish it
- To publish a version that's already released, run "VS Code の拡張機能を公開する" manually with the version

To publish by hand, run `npx @vscode/vsce@4.1.1 publish --packagePath packages/vscode/liminalia-<version>.vsix -p <token>` and
`npx ovsx@1.4.0 publish packages/vscode/liminalia-<version>.vsix -p <token>`.
