Skip to content

Tasks and the project terminal

Audience: anyone who runs checks, tests or generators from the IDE, and language authors who want a one-click "build" · ~6 min read · Prerequisites: The strukts CLI

What it is

The IDE's task list (Tools > Run Task…, or Task: Run Task… in the command palette) offers the strukts command-line verbs for the folder you opened:

Task Runs
strukts: check strukts check — the same findings as the Problems panel
strukts: generate strukts generate — writes generated files to build/generated
strukts: test strukts test
strukts: verify strukts verify — check, tests and a generator dry run in one report
strukts: package strukts package

A language can add tasks of its own, such as "verify, then generate". They appear in the same list, with the language's name beside them.

The command struktJS: Open Terminal in Project (command palette; Tools > Terminal opens a plain terminal) opens a terminal in the folder with strukts already on its PATH. Run Task… lists the struktJS tasks and the tasks of your own tasks.json; the TypeScript compiler's tsc build and watch tasks of the bundled TypeScript extension are hidden.

When you'd use it

  • You want a keyboard shortcut or the palette for "run the tests", without opening the Tests pane.
  • You want findings from a whole project in the Problems panel, including models you have not opened.
  • You want the IDE to run exactly what your CI runs, because it is the same program.

How to use it

  1. Open a project (File > Open Project…, or a sample). Tasks run against the project that is open in struktJS, in that project's own folder; a bundled sample runs by its shipped name. With no project open, they fall back to the workspace folder.
  2. Choose Tools > Run Task…, then the struktJS group, then a task.
  3. Read the output in the Task tab of the bottom panel.
  4. For check and verify, open the Problems panel: each finding is listed under its model file with its line and column. Double-click one to open the model with the cursor on that node.

To run a task from a key or a script, add it to .theia/tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    { "type": "strukts", "verb": "check", "label": "check models", "problemMatcher": ["$strukts"] },
    { "type": "strukts", "task": "build-preview", "label": "build the preview" }
  ]
}

verb is one of the five verbs; task is the name of a language-declared task instead. args adds command-line arguments.

What to know

  • Where it runs. In the browser IDE the task runs on the machine hosting the IDE, not on the machine with the browser. In the desktop app both are the same machine.
  • Project languages ask first. A folder with its own *.lang.js language file runs JavaScript when it is loaded. The first task you run in such a folder asks once per session; Cancel runs nothing. Language tasks of such a folder only appear in the list after you have agreed. See Trusting project code.
  • Positions can drift. Problems from a task point at the line and column of the saved file at the time the task ran. If you edit the model afterwards, run the task again.
  • Run, Tests pane and tasks overlap on purpose. Run and the Tests pane run inside the editor and show more detail. Tasks are the batch path: the same output as CI.
  • Exit codes. A task fails when the CLI exits non-zero (3 for check findings, 4 for generator failures, 5 for failing tests); see CLI exit codes and JSON.

Tasks a language declares

A language lists named tasks, each a chain of steps. A step is a CLI verb or an external command; the task stops at the first step that fails and reports that step's exit code.

tasks: [
  {
    name: "build-preview",
    label: "Verify, then generate the preview",
    steps: [{ verb: "verify" }, { verb: "generate" }],
  },
  { name: "compile", steps: [{ verb: "generate", args: ["--output", "${out}"] }, { command: "tsc", args: ["-p", "${out}"] }] },
],
  • ${project} is the project folder and ${out} is build/generated inside it. Any other ${…} is passed through unchanged.
  • A task name starts with a letter and has no spaces.
  • The Grid Robot language ships build-preview as a worked example; open the Maze Explorer sample as a folder to see it.
  • From a terminal: strukts tasks --project-dir . lists them, strukts task build-preview --project-dir . runs one.

An external command runs with your privileges. A language you did not write, or a project language, deserves the same care as any script you download.