Using the features of the IntelliJ plugin
Click on the below links to find information on the various capabilities that are facilitated by the IntelliJ Ballerina plugin for the development process.
- Running Ballerina programs
- Debugging Ballerina programs
- Viewing the sequence diagram
- Importing modules on the fly
- Importing unambiguous modules
- Formatting Ballerina codes
- Viewing documentation
- Adding annotation fields via suggestions
- Using file templates
- Using code snippet templates
- Checking spellings
- Analyzing semantics
- Code folding
Running Ballerina programs
You can run Ballerina main/service programs with a single click without adding or changing any configurations.
Click on the below links for 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.
Click the green color icon located near the main function.
Click the corresponding Run
This executes the main function of the Ballerina file and displays the output in the Run window.
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.
Click the green color icon located near the definition of the service.
Click the corresponding Run *
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.
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.
- 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 () in the top right corner of the IDE window as shown in the below example.
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.
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.
Formatting Ballerina codes
You can reformat the Ballerina codes by pressing the Ctrl+Alt+L keys.
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.
Adding annotation fields via suggestions
You can add annothation fields to your code uisng the annotation field names that are suggested inside annotation attachments.
Using file templates
Three types of Ballerina file templates are available.
- Ballerina Main - contains a sample main program
- Ballerina Service - contains a sample service
- Empty File - contains an empty file
Using code snippet templates
Code snippet templates contain boilerplate codes and allows you to write your code efficiently.
The spell-checker is enabled for all identifiers. You can rename all of the definitions and references as well.
The Ballerina IDEA plugin provides capabilities to diagnose and analyze semantics of your Ballerina programs through the Ballerina Language Server.
You expand/collapse the following Ballerina code segments using the icons in the IntelliJ IDE.
- functions and object functions
- markdown documentation
- multiline comments