Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support invoking actions directly in Ballerina shell #41587

Merged
merged 6 commits into from
Mar 20, 2024

Conversation

nipunayf
Copy link
Contributor

@nipunayf nipunayf commented Oct 27, 2023

Purpose

Since Ballerina does not allow actions to be invoked at the module level, the current implementation has the limitation of invoking an action. As a workaround, this PR wraps the action in a function and returns the value to the module-level declared variable.

Fixes #39960
Fixes #39893

Approach

The new implementation wraps the action inside a function and returns the value to a module-level variable. Considering the user's input http:Response response = check clientEndpoint->get("/entries");, the shell generates the following snippet as a workaround for the issue.

function () returns error|http:Response __shell_wrapper__0 = function() returns error|http:Response {
    http:Response response = check clientEndpoint->get("/entries");
    return response;
};
http:Response response = check __shell_wrapper__0();

Samples

The following types of actions are now supported in Ballerina shell with this PR.

$= string returnValue = myClient->invoke("input");

$= string returnValue = myClient ->/root/name("input");

$= future<int> futureResult = start name();

Remarks

Still, the user cannot assign the output of an action to a var variable. This requires additional implementation since we have to intact the semantic model to determine the return type of the action and then generate the custom function.

Additionally, since the shell generates a function for each action, those function names are now disallowed for the user.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@nipunayf nipunayf requested a review from mohanvive as a code owner October 27, 2023 09:00
@nipunayf nipunayf added the Team/LanguageServer Language Server Implementation related issues. #Compiler label Oct 27, 2023
@codecov
Copy link

codecov bot commented Oct 28, 2023

Codecov Report

Attention: Patch coverage is 67.85714% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 76.67%. Comparing base (991f718) to head (71349f5).
Report is 20 commits behind head on master.

Files Patch % Lines
...ina/shell/snippet/factory/BasicSnippetFactory.java 70.83% 3 Missing and 4 partials ⚠️
...ava/io/ballerina/shell/parser/ParserConstants.java 0.00% 0 Missing and 1 partial ⚠️
...va/io/ballerina/shell/parser/SerialTreeParser.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #41587       +/-   ##
=============================================
+ Coverage      0.00%   76.67%   +76.67%     
- Complexity        0    53101    +53101     
=============================================
  Files             9     2884     +2875     
  Lines            35   200222   +200187     
  Branches          0    26081    +26081     
=============================================
+ Hits              0   153529   +153529     
- Misses           35    38260    +38225     
- Partials          0     8433     +8433     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nipunayf nipunayf force-pushed the shell-actions branch 2 times, most recently from 304c027 to 05e40dd Compare November 20, 2023 11:32
Copy link

github-actions bot commented Dec 5, 2023

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Dec 5, 2023
@nipunayf nipunayf removed the Stale label Dec 6, 2023
@nipunayf nipunayf added Team/CompilerFETools Semantic API, Formatter, Shell and removed Team/LanguageServer Language Server Implementation related issues. #Compiler labels Dec 17, 2023
@nipunayf nipunayf requested a review from hasithaa January 2, 2024 16:08
@nipunayf nipunayf force-pushed the shell-actions branch 2 times, most recently from 054d6fa to 804049f Compare January 2, 2024 18:27
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jan 18, 2024
@nipunayf nipunayf removed the Stale label Jan 19, 2024
Copy link

github-actions bot commented Feb 3, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Feb 3, 2024
@nipunayf nipunayf removed the Stale label Feb 4, 2024
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Feb 19, 2024
@nipunayf nipunayf removed the Stale label Feb 20, 2024
Copy link

github-actions bot commented Mar 6, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Mar 6, 2024
@nipunayf nipunayf removed the Stale label Mar 7, 2024
@lochana-chathura lochana-chathura added this to the 2201.9.0 milestone Mar 18, 2024
Copy link
Member

@lochana-chathura lochana-chathura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Added a few minor suggestions.

@lochana-chathura lochana-chathura merged commit ffe0d36 into ballerina-platform:master Mar 20, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFETools Semantic API, Formatter, Shell
Projects
None yet
5 participants