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
- 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.
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.
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.
- 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.
- Click Ballerina and then click Auto Import.
- 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 annotation fields to your code using 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