Message Service

The message service allows you to show messages, interactive dialogues and progress information to the user. You can get the MessageService injected and call either info, warn or error on it to report your message (see code example below):

@inject(MessageService) private readonly messageService: MessageService'Hello World!')

By default, Theia will display messages as toast notifications in the bottom right corner. Below you can see screenshots of the different message types (info, warn and error). Please note that you can easily adopt Theia to implement a different behavior for displaying messages by providing a custom MessageClient.


Message Service - info


Message Service - warning


Message Service - error

By default, notifications will be displayed until the user closes them. You can optionally define a time out after which messages will be closed automatically:'Say Hello with timeout',{timeout: 3000})

Optionally, you can also add actions that the user can execute. In case the user executes an action, the message service call will resolve to the action string which was handed over.

In the following code example, we provide the two actions “Say Hello again!” and “Cancel”. We react to the action “Say hello again!” by posting yet another message, “Cancel” will be ignored.

@inject(MessageService) private readonly messageService: MessageService

 .error("Hello World!", "Say Hello again!", "Cancel")
 .then((action) => {
   if (action === "Say Hello again!")"Hello again!");

The corresponding toast notification will look like this:

Message Service - user action

When the user selects “Say Hello again”, another toast notification will be shown:

Message Service - after user action

Progress Reporting

The message service also allows you to report progress on an ongoing operation. You can incrementally update a progress bar and the message while the toast notification remains visible until the operation is done. The following example opens a progress bar and updates the status three times before it is completed. Please see the TypeDoc of MessageService for more detailed information.

   text: `Doing something`,
 .then((progress) => {
   // Do something{
     message: "First step completed",
     work: { done: 10, total: 100 },
   // Do something{
     message: "Next step completed",
     work: { done: 80, total: 100 },
   // Do something{
     message: "Complete",
     work: { done: 100, total: 100 },

Note that progress.cancel is also used to signal that a progress is complete. The code example above will be displayed like this:

Message Service - progress reporting
Go to previous Page : Label ProviderGo to next page : Events