ballerina-platform / plugin-intellij

Ballerina extension for IntelliJ IDEA.
Apache License 2.0
118 stars 4 forks source link

Add program execution and testing capabilities for the swan lake plugin version #47

Closed ThemiraChathumina closed 5 months ago

ThemiraChathumina commented 5 months ago

Purpose

This PR introduces functionality for executing programs and running Ballerina tests in IntelliJ IDE. Additionally, a language settings page has been added, allowing users to switch between the system Ballerina version and other local versions. Users can also customize their run configurations with environment variables, command options, and program arguments. Related to https://github.com/ballerina-platform/plugin-intellij/issues/46

Approach

Detecting system ballerina version

This will be accomplished by calling bal home in Linux and Mac environments. In Windows, paths will be constructed by detecting the environment variable that stores the Ballerina path, since the output of the bal home command in Windows is truncated. In all environments, the Ballerina version is detected by calling the bal -v command.

Switching between ballerina versions

Users can switch between versions via the language settings page. The Ballerina version set in this section will be used globally across all IntelliJ projects. Initially, the system Ballerina version is detected. If no version is available, the user will be informed. Users can also choose another Ballerina SDK path as their SDK by selecting a checkbox. As long as this checkbox remains selected, the specified Ballerina path will be used. If the specified path is not available, the system Ballerina version will be used instead. Upon switching SDK paths, a restart notification will be triggered.

Run configurations and test configuraions

The function public String getBallerinaPath(Project project) in the class BallerinaSdkService provides the path to the ballerina executable for running Ballerina commands. For each run configuration type, a run profile state will be created. This state (Which is a command line state) executes the Ballerina commands (bal run and bal test) with the provided environment variables, command options, and program arguments through an OSProcessHandler. Users can modify these settings on the run configuration settings page for each configuration type. If the ballerina executable path is not available, a notification will be displayed. When executing Ballerina files within packages, the package path will be used; otherwise, the individual Ballerina file will be executed. Users can run package tests, module tests, and individual test functions separately through the user interface.

Samples

Language settings page

image

Selecting another sdk path

image

image

Invalid sdk path

image

No available sdk

image

image

Status bar icon displaying currently using ballerina version

image

Run configuration settings page

image image

Program execution

Right click actions

image

Gutter icons

image image image

Execution

Individual file

image

Package

image

Package tests

image image

Module tests

image image