Plugins and devkits¶
Built-in languages ship as plugins under plugins/. A plugin is just a folder; there is no per-plugin
package.json, build step or frontend module. Languages are discovered automatically by src/lang-library.ts.
Anatomy of a plugin¶
plugins/lang-money/
project.json { name, description } -- the plugin's demo project
languages/
index.ts default export: the language definition
concepts.tsx BaseConcept subclasses
models/
money-demo/
model.json { label, description, imports: [...] }
money-demo.model.py the demo program (source text)
tests/ optional: *.test.mjs files vitest picks up
languages/: every file here that exports a plain{ name, concepts, ... }object becomes a language. One file may export several. Soplugins/lang-core/languages/is a set of small languages, one per topic (concepts-symbols.tsx,concepts-operators.tsx,concepts-control-flow.tsx, and so on).models/: demo programs for the plugin's own language, picked up by "Load Sample...". A plugin with exactly one demo hoistsproject.jsonto the plugin root, as above; a plugin with several demos (lang-entities) keeps aproject.jsonin each model folder and nestsmodel.jsonand the program in amodel/subfolder. Generic samples that are not tied to one language live in the top-levelsamples/<name>/instead.tests/:plugins/*/tests/*.test.mjsare included byvitest.config.jsautomatically.
A model's model.json can declare imports: [{ "qualifiedName": "heating" }] to say which languages the program
uses.
The language definition¶
import { conceptsFromModule } from "../../../src/base-concept.ts";
import * as concepts from "./concepts.tsx";
export default {
name: "money",
namespace: "money",
displayName: "Money",
description: "Currency-typed arithmetic demo language.",
concepts: conceptsFromModule(concepts),
};
| Field | Meaning |
|---|---|
name, namespace, displayName, description |
Identity and labels. |
concepts |
From conceptsFromModule(mod) (all exported concept classes) or an explicit list of conceptMetaFromClass(Cls). |
_importNames |
Names of other languages whose concepts this one looks up. Doubles as the dependency list for load order: a language declaring _importNames: ["core"] always registers after core. |
persistenceGrammar |
Grammar of the model files: "python" (default), "javascript", ... See Persistence grammars. |
transformations[].extension |
on the default generate transformation: the extension of the generated files; "html" says the output is a runnable document ("Open Preview"). Replaces previewFormat / generatedExtension. See Evaluation and generation. |
reservedWords, commonModules, nullLiteralGlyph, stringQuoteChar, tooltipsEverywhere, supportsHostExecution, hostExecutorId, reportUnresolvedReferences |
Language-wide behaviour switches. |
subtypes, generators, reductions, weavingRules, postProcess, generatorPlan |
Data-form rules; see Evaluation and generation. |
onActivate(lang) |
One-time hook run after the language is constructed and its imports resolved. The place for setEditorOverlay, setTypesystemOverlay and the like. Not persisted. |
Two module-level exports next to the default export control discovery:
export const tier = "core"; // "core" is always loaded at boot; "demo" (the default) loads on demand
export const hidden = true; // excluded from the installable list and from the core/demo lists
A hidden language can still be loaded by explicit name (the pattern and scopeflow languages are hidden for this
reason). export const defaultLanguage = true marks the workbench's fallback language.
Leave out of a demo language anything its model files do not need: lang-money and lang-simplest import no Core
concepts at all, so each defines its own tiny root and comment concept. If the model files are Python-syntax text, the
plugin must import the Python grammar once (import "../../lang-python/grammar/ts-parser.ts"), as lang-simplest
does; plugins that import Core get it through Core.
Library models: shared code a hook imports by name¶
A concept file often needs code that several concepts share (Core's type walks are the first example). Put it in a library
model: a folder plugins/<plugin>/models/<name>/ whose model.json says "role": "library" and which holds one source file,
<name>.js (or .ts, or the folder's only source file). It is ordinary JavaScript, importable as it is, with no header line.
// plugins/lang-core/models/core-typewalk/model.json
{ "role": "library", "label": "Core type walks" }
// any concept file in the same plugin
import { walkComprehension } from "core-typewalk"; // the model's folder name
import { walkComprehension } from "lang-core.core-typewalk"; // the same, qualified by its plugin
The name resolves in every build and test (scripts/vite-library-models-plugin.mjs: the webview, the embed build, the CLI bundle,
vitest). It fails closed: a bare name that two plugins both declare must be qualified, a name that is also an installed package
is an error, and a library folder with no source file or several is an error. Only libraries that ship in this repository resolve;
a project's own libraries do not run yet.
A library is not a sample or a project: the Load Sample menu, strukts list and the sample sweeps skip it. A customer build
that prunes plugins keeps a library with the plugin that holds it, so import a library only from its own plugin (a library
imported across plugins would need both plugins kept). The source-scanning ratchets still read library files
(tests/library-models-lib.mjs), so moving code into one does not take it out of a ratchet.
Devkits¶
A devkit bundles several sibling languages into one installable language. It is a JSON file
plugins/<name>/<name>.devkit.json; today the only one is plugins/lang-core/core.devkit.json.
{
"name": "core",
"displayName": "Core",
"description": "Core language constructs: symbols, operators, control flow, functions and lists.",
"tier": "core",
"defaultLanguage": true,
"supportsHostExecution": true,
"hostExecutorId": "python",
"reservedWords": ["false", "none", "true", "and", "..."],
"commonModules": ["math", "os", "sys", "..."],
"languages": ["core.symbols", "core.operators", "core.control-flow", "core.functions",
"core.collections", "core.modules", "core.exceptions", "core.advanced", "core.pattern-matching"]
}
mergeDevkitLanguages (src/devkit.ts) unions the members' concepts, checks, constraints, generators and subtypes
into one synthetic language, and the devkit-level fields (reservedWords, commonModules, supportsHostExecution,
tooltipsEverywhere, ...) belong to the bundle, not to any member. Every language named in languages is
automatically treated as hidden, so only core shows up in the installable list and everything else imports
core. plugins/lang-core/core.ts gives non-plugin code (tests, lang-genplan) synchronous access to the same merged
language through the same helper.
Registries and extension points¶
Plugins extend the workbench without engine edits through registries. The ones languages use most:
| Registry | Purpose |
|---|---|
registerGrammar() (src/grammar-registry.ts) |
A new persistence grammar. See Persistence grammars. |
registerClosedSlotKinds() (src/slot-kinds.ts) |
Slot kinds that accept only listed concept categories. |
registerImportCompletionSource() (src/import-completion-registry.ts) |
Module and member names offered while completing an import. |
registerDataflowShapeFloor() (src/dataflow.ts) |
Lang-less dataflow shapes. |
Keep plugin code behind the language-agnostic boundary: nothing under src/ may import a plugin or name a concept
head. See Language-agnostic core.
Hot-reloadable dev-plugins¶
A dev-plugin is a single self-contained .ts or .tsx file anywhere on the machine running the Theia backend,
outside this repo's plugins/ tree. You edit it in any editor and the running IDE picks up the change with no build
and no restart.
- Folders are configured in
~/.struktjs/plugin-folders.json;~/.struktjs/dev-plugins/is always included, so you can drop a file there with no setup. - The backend (
theia-extension/src/node/struktjs-plugin-loader.ts) compiles each file to plain JavaScript on request withts.transpileModule(no bundler), serves it at/api/struktjs/plugins/languages/<name>.js, and watches the folders, streaming change events so the frontend (src/dynamic-lang-loader.ts) re-imports the plugin. - The Language Plugins view lists discovered plugins and loads or reloads them. Discovering a plugin only makes it available; loading is a separate, explicit step.
- A plugin file exports a
Languageas its default export and/or a namedcontributionsexport withcommands,menuItems,removeMenuItemsandtools, registered throughwindow.StruktJS.contribute. A file with onlycontributionsis a pure IDE-customization plugin.
The one hard constraint: a dev-plugin is loaded with a plain import() and has no module resolution of its own, so it
can reach the engine only through window.StruktJS.authoring, never through relative imports. That object exposes h,
Fragment, Text, Br, Child, Computed, Indent, Children, WhenPresent, WhenAbsent, Optional, Grid,
Diagram, Table, ChildSlot, Ref, Prop, child, children, optional, ref, prop, BaseConcept, registerConceptClass, conceptMetaFromClass,
registerLanguage, walkNodes, walkConceptHierarchy, ModelNode, NodeList and Model.
This is the right tool for building a new standalone language. It does not help when iterating on a built-in plugin, which is split across files with real relative imports; for that, use the fast webview loop in Setup and workflow.
Dev-plugin code runs with the IDE's privileges, so loading is gated by a content-hash trust prompt. See Security and privacy.
Checklist for a new built-in plugin¶
- Create
plugins/lang-<name>/languages/index.ts(+concepts.tsx) as above. - Add a demo under
models/<name>-demo/withmodel.jsonand a.model.pyprogram. - Run
npm run stage:active-roots, thennpm testandnpm run lint:concepts. The sample smoke tests load and evaluate every bundled sample. - If your language is meant to be user-visible, check it appears in "Load Sample..." and in the language list.
Alternative Explorer views¶
A plugin can add a named tree to the Explorer with registerExplorerView (src/explorer-views.ts), for example "By
concept" or "Favourites":
const dispose = registerExplorerView({
id: "favourites",
label: "Favourites",
icon: "★",
priority: 10, // higher first in the switcher
build: (project) => [
{ id: "m1", label: "Console Cookbook", onActivate: () => open("console-cookbook") },
{ id: "grp", label: "Recent", children: () => recentNodes(project) },
],
});
Once any view is registered, the Explorer shows a switcher above the tree with "Files" and one tab per view; until then
nothing changes. A node with a children function is a folder, and its children are built only when the user expands it
(so a large view costs nothing until opened). Nodes may carry an icon, title, onActivate and hover actions.
Registering the same id again replaces the view, and the returned function removes it; if the active view is removed the
Explorer falls back to the file tree. A build that throws shows an error row instead of breaking the pane. build(project, ctx) also receives ctx.openRoot(model, root) to open a model root in the editor. The active view is
remembered per browser (local storage) and restored once its view is registered; an id that no longer exists falls back to Files. Switch from the tabs, or with the Next Explorer View command (command palette), which cycles Files and then each view
(it does nothing until a view is registered, and in Theia it works with focus in the Explorer, not only in the editor). struktJS ships two views: By concept, which groups every model root by its
root node's concept, and Structure, which lists the ITreeViewable nodes inside each root (ctx.openNode(model, root, node) opens a root and focuses one node).