Using the Features of the IntelliJ Plugin

The below sections include information on the various capabilities that are facilitated by the IntelliJ Ballerina plugin for the development process.

Running Ballerina Programs

You can run Ballerina main/service programs with a single click without adding or changing any configurations.

The below sections include instructions on how to run different elements of a Ballerina file.

Running the Main Method

Follow the steps below to run the main function of a Ballerina file.

  1. Click the green color icon located near the main function.

    Click the Run Application icon

  2. Click the corresponding **Run ** command.

    Click the Run command

This executes the main function of the Ballerina file and displays the output in the Run window.

Output of running the main function

Tip: Alternatively, you can right click on the name of the file and run the main method of it.

Running Ballerina Services

Follow the steps below to run a service of a Ballerina file.

  1. Click the green color icon located near the definition of the service.

  2. Click the corresponding **Run **** command.

This starts the service and displays the output in the Run window. If you have multiple services in the Ballerina file, this starts all of them.

Output of running a service

Tip: Alternatively, you can right click on the name of the file and run the service(s) of it.

Debugging Ballerina Programs

You can debug Ballerina main/service programs with a few clicks.

Debug Ballerina programs


  • Stepping over code lines in non-blocking paths (eg: action invocations) will not pause VM on next line
    • workaround: manually put a breakpoint to next line
  • There are some cases where stepping over gives unexpected behavior
    • Eg: When there are multiple workers and a wait expression waiting for them, even though step over hit and pass wait line in source, workers are not yet finished execution.

Viewing the Sequence Diagram

The underlying language semantics of Ballerina were designed by modeling how independent parties communicate via structured interactions. Subsequently, every Ballerina program can be displayed as a sequence diagram of its flow including endpoints as well as synchronous and asynchronous calls.

To view the sequence diagram of a Ballerina file, click the (design view icon) in the top right corner of the IDE window as shown in the below example.

HTTP circuit breaker sequence diagram

Importing Modules on the Fly

You can add import declarations to your Ballerina programs on the fly. When you select the module name from the lookup list, the module declaration will be added automatically.

Import modules on the fly

Importing Unambiguous Modules

When you copy and paste Ballerina code to IntelliJ, this feature allows you to import unambiguous imports. You can apply these imports by clicking on the module name and pressing Alt + Enter keys.

Note: This is disabled by default since this might cause issues if the file contains grammar mistakes. Follow the steps below to enable it.

  1. Open IntelliJ, click IntelliJ IDEA in the top menu, click Preferences, and then click Languages and Frameworks.
    • Tip: If you are using Windows, click File, click Settings, and then click Languages and Frameworks.
  2. Click Ballerina and then click Auto Import.
  3. Select the Add unambiguous imports on the fly checkbox and click OK.

Import unambiguous modules

Formatting Ballerina Codes

You can reformat the Ballerina codes by pressing the Ctrl+Alt+L keys.

Formatting Ballerina codes

Viewing Documentation

You can view the documentation of a function, remote function, etc. by pressing the Ctrl+Q keys or by hovering over the element while pressing the Ctrl key.

Viewing documentation

Adding Annotation Fields via Suggestions

You can add annotation fields to your code using the annotation field names that are suggested inside annotation attachments.

Adding annotation fields via suggestions

Using File Templates

Three types of Ballerina file templates are available.

  1. Ballerina Main - contains a sample main program
  2. Ballerina Service - contains a sample service
  3. Empty File - contains an empty file

Using file templates

Using Code Snippet Templates

Code snippet templates contain boilerplate codes and allows you to write your code efficiently.

Using code snippet templates

Checking Spellings

The spell-checker is enabled for all identifiers. You can rename all of the definitions and references as well.

Checking spellings

Analyzing Semantics

The Ballerina IDEA plugin provides capabilities to diagnose and analyze semantics of your Ballerina programs through the Ballerina Language Server.

Analyzing semantics

Code Folding

You expand/collapse the following Ballerina code segments using the icons in the IntelliJ IDE.

  • imports
  • services
  • objects
  • records
  • functions and object functions
  • annotations
  • markdown documentation
  • multiline comments

Code folding

What’s Next?

  • For more information on the IntelliJ IDEA Ballerina plugin, see IntelliJ IDEA Ballerina Plugin.
  • For information on all the tools and IDEs that are supported by Ballerina, see Learn.