Skip to content

Commit

Permalink
Add tests to create function CA
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Feb 6, 2024
1 parent 6a5b90b commit 43a099e
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ public void visit(BlockStatementNode node) {

@Override
public void visit(NamedWorkerDeclarationNode namedWorkerDeclarationNode) {
Optional<Symbol> symbol = semanticModel.symbol(namedWorkerDeclarationNode);
symbol.ifPresent(value -> checkAndSetTypeResult(((WorkerSymbol) value).returnType()));
semanticModel.symbol(namedWorkerDeclarationNode)
.ifPresent(value -> checkAndSetTypeResult(((WorkerSymbol) value).returnType()));
}

@Override
Expand All @@ -420,7 +420,12 @@ public void visit(ReturnStatementNode returnStatementNode) {

// Get function type symbol and get return type descriptor from it
returnStatementNode.parent().accept(this);
if (resultFound && returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) {

if (!resultFound) {
resetResult();
return;
}
if (returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) {
FunctionTypeSymbol functionTypeSymbol = (FunctionTypeSymbol) returnTypeSymbol;
functionTypeSymbol.returnTypeDescriptor().ifPresentOrElse(this::checkAndSetTypeResult, this::resetResult);
}
Expand Down Expand Up @@ -521,8 +526,7 @@ public void visit(ImplicitAnonymousFunctionExpressionNode expr) {

@Override
public void visit(ExplicitAnonymousFunctionExpressionNode explicitAnonymousFunctionExpressionNode) {
Optional<TypeSymbol> typeSymbol = semanticModel.typeOf(explicitAnonymousFunctionExpressionNode);
typeSymbol.ifPresent(this::checkAndSetTypeResult);
semanticModel.typeOf(explicitAnonymousFunctionExpressionNode).ifPresent(this::checkAndSetTypeResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ public Object[][] dataProvider() {
{"create_function_in_worker2.json"},
{"create_function_in_worker3.json"},
{"create_function_in_worker4.json"},
{"create_function_in_worker5.json"},

{"create_function_in_explicit_anonymous_function1.json"},
{"create_function_in_explicit_anonymous_function2.json"},
{"create_function_in_explicit_anonymous_function3.json"},
{"create_function_in_explicit_anonymous_function4.json"}
{"create_function_in_explicit_anonymous_function4.json"},
{"create_function_in_explicit_anonymous_function5.json"}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"position": {
"line": 22,
"character": 22
},
"source": "create_function_in_explicit_anonymous_function.bal",
"expected": [
{
"title": "Create function 'foo(...)'",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 25,
"character": 1
},
"end": {
"line": 25,
"character": 1
}
},
"newText": "\n\nfunction foo() returns int {\n return 0;\n}"
}
],
"resolvable": true,
"data": {
"extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension",
"codeActionName": "Create Function",
"fileUri": "create_function_in_explicit_anonymous_function.bal",
"range": {
"start": {
"line": 22,
"character": 19
},
"end": {
"line": 22,
"character": 24
}
},
"actionData": {
"key": "node.range",
"value": {
"start": {
"line": 22.0,
"character": 19.0
},
"end": {
"line": 22.0,
"character": 24.0
}
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
{
"range": {
"start": {
"line": 19,
"line": 25,
"character": 1
},
"end": {
"line": 19,
"line": 25,
"character": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"position": {
"line": 22,
"character": 22
},
"source": "create_function_in_worker.bal",
"expected": [
{
"title": "Create function 'foo(...)'",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 25,
"character": 1
},
"end": {
"line": 25,
"character": 1
}
},
"newText": "\n\nfunction foo() returns int {\n return 0;\n}"
}
],
"resolvable": true,
"data": {
"extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension",
"codeActionName": "Create Function",
"fileUri": "create_function_in_worker.bal",
"range": {
"start": {
"line": 22,
"character": 19
},
"end": {
"line": 22,
"character": 24
}
},
"actionData": {
"key": "node.range",
"value": {
"start": {
"line": 22.0,
"character": 19.0
},
"end": {
"line": 22.0,
"character": 24.0
}
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ function createFunctionInWorker() {
var fn4 = function() returns module1:TestRecord2 {
return foo();
};

var fn5 = function() returns function () returns int {
return function () returns int {
return foo();
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ function createFunctionInWorker() {
worker D returns module1:TestRecord2 {
return foo();
}

fork {
worker E returns int {
return foo();
}
}
}

0 comments on commit 43a099e

Please sign in to comment.