The code worker holds the project’s files in memory, with unsaved edits, and TypeScript. It is the only place where the compiler is loaded.
A worker entry
Add a second entry to the manifest and to the build.
A transformer also gets
edit, which records the changes: replace(node, text), insertBefore, insertAfter, insertAt(offset, text), remove(node), removeLines(node).
Call them from the page
code.edit returns a HistoryCommand (or undefined when nothing changes). Push it on the file’s history, or group several in a transaction: see history.
The model an analyzer returns crosses to the page as plain data: no syntax nodes, no functions.
Codegen targets
A codegen target is how one kind of app keeps part of its state in code. The ECS plugin’s target reads an app’s entry file as a list of entities, components and systems, and writes back operations such as “add a component to this entity”.- When several targets apply to an app, the highest
prioritywins (selectTarget). - The Scene screen shows the editor a plugin contributed to
SCENE_EDITORSfor the target in use. - To make the ECS widgets (hierarchy, inspector, systems, 2D scene) edit another place than the entry file’s
main, contribute to the ECS plugin’secs.sourcesinstead: a location is a file and a function body ({ kind: 'method', class: 'Level1', method: 'setup' }), and the widgets keep working unchanged. The scene plugin edits the selected scene’ssetupthis way.
Item owners
Items are exports of the game’s code that the editor lists: components, systems, and whatever a plugin describes. The editor extracts for each one its name, documentation, constructor parameters and fields, with their types and defaults, from the code and its TSDoc. What an item is belongs to a plugin, its owner. The ECS plugin owns the@component and @system tags; the core knows nothing about them.
extract returns the plugin’s own data about an export, stored under the plugin’s name. Read items in the page with the catalog:
nf_modules, read-only). The catalog keeps a cache in .nanoforge/editor/cache/meta/ and extracts again only what changed.
Problems
A plugin reports problems (shown in the Problems panel and in the code editor) throughDiagnosticsServiceToken, and JSON files get completion and validation from a schema contributed to JSON_SCHEMAS.