The Che-Theia IDE allows users to define custom commands in a devfile that are then available when working in a workspace.

The following is an example of the commands section of a devfile.

commands:
- name: theia:build
  actions:
  - type: exec
    component: che-dev
    command: >
              yarn
    workdir: /projects/theia
- name: run
  actions:
  - type: vscode-task
    referenceContent: |
            {
             "version": "2.0.0",
             "tasks":
             [
              {
               "label": "theia:watch",
                "type": "shell",
                "options": {"cwd": "/projects/theia"},
                "command": "yarn",
                "args": ["watch"]
              }
             ]
            }
- name: debug
  actions:
  - type: vscode-launch
    referenceContent: |
            {
             "version": "0.2.0",
             "configurations": [
              {
               "type": "node",
               "request": "attach",
               "name": "Attach by Process ID",
               "processId": "${command:PickProcess}"
              }
             ]
            }
Che commands

theia:build

  • The exec type implies that the Che runner is used for command execution. The user can specify the component in whose container the command is executed.

  • The command field contains the command line for execution.

  • The workdir is the working directory in which the command is executed.

Visual Studio Code (VS Code) tasks

run

  • The type is vscode-task.

  • For this type of command, the referenceContent field must contain content with task configurations in the VS Code format.

  • For more information about VS Code tasks, see the Task section on the Visual Studio User Guide page.

VS Code launch configurations

debug

  • The type is vscode-launch.

  • It contains the launch configurations in the VS Code format.

  • For more information about VS Code launch configurations, see the Debugging section on the Visual Studio documentation page.

For a list of available tasks and launch configurations, see the tasks.json and the launch.json configuration files in the /workspace/.theia directory where the configuration from the devfile is exported to.

Che-Theia task types

Two types of tasks exist in a devfile: tasks in the VS Code format and Che commands. Tasks from the devfile are copied to the configuration file when the workspace is started. Depending on the type of the task, the task is then available for running:

  • Che commands: From the TerminalRun Task menu in the configured tasks section, or from the My Workspace panel

  • Tasks in the VS Code format: From the Run Tasks menu

To run the task definitions provided by plug-ins, select the TerminalRun Task menu option. The tasks are placed in the detected tasks section.

Running and debugging

Che-Theia supports the Debug Adapter Protocol. This protocol defines a generic way for how a development tool can communicate with a debugger. It means Che-Theia works with all implementations.

Prerequisites
  • A running instance of Eclipse Che. To install an instance of Eclipse Che, see Che 'quick-starts'.

Procedure

To debug an application:

  1. Click DebugAdd Configuration to add debugging or launch configuration to the project.

    che theia basics 1
  2. From the pop-up menu, select the appropriate configuration for the application that you want to debug.

    che theia basics 2
  3. Update the configuration by modifying or adding attributes.

    che theia basics 3
  4. Breakpoints can be toggled by clicking the editor margin.

    che theia basics 3 b
  5. Open the context menu of the breakpoint to add conditions.

    che theia basics 3 c
  6. To start debugging, click ViewDebug.

    che theia basics 4
  7. In the Debug view, select the configuration and press F5 to debug the application. Or, start the application without debugging by pressing Ctrl+F5.

    che theia basics 5

Editing a task and launch configuration

Procedure

To customize the configuration file:

  1. Edit the tasks.json or launch.json configuration files.

  2. Add new definitions to the configuration file or modify the existing ones.

    The changes are stored in the configuration file.
  3. To customize the task configuration provided by plug-ins, select the TerminalConfigure TasksS menu option, and choose the task to configure. The configuration is then copied to the tasks.json file and is available for editing.

Tags: