Skip to content

Commit

Permalink
Merge pull request #516 from LakshanWeerasinghe/fix-#456
Browse files Browse the repository at this point in the history
Get the enclosed resource, remote function definition for a given position
  • Loading branch information
hasithaa authored Dec 6, 2024
2 parents a2b9293 + ff60b66 commit 717db29
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package io.ballerina.flowmodelgenerator.core;

import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode;
import io.ballerina.compiler.syntax.tree.ModulePartNode;
import io.ballerina.compiler.syntax.tree.NonTerminalNode;
import io.ballerina.compiler.syntax.tree.SyntaxKind;
import io.ballerina.projects.Document;
import io.ballerina.tools.text.LinePosition;
import io.ballerina.tools.text.LineRange;
Expand All @@ -47,7 +47,7 @@ public LineRange findEnclosedNode() {
int positionOffset = PositionUtil.getPositionOffset(PositionUtil.toPosition(position), document.syntaxTree());
TextRange textRange = TextRange.from(positionOffset, 1);
NonTerminalNode nonTerminalNode = modulePartNode.findNode(textRange);
while (nonTerminalNode != null && nonTerminalNode.kind() != SyntaxKind.FUNCTION_DEFINITION) {
while (nonTerminalNode != null && !(nonTerminalNode instanceof FunctionDefinitionNode)) {
nonTerminalNode = nonTerminalNode.parent();
}
if (nonTerminalNode == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "current package reference",
"filePath": "proj_1/services.bal",
"position": {
"line": 5,
"offset": 24
},
"response": {
"filePath": "proj_1/services.bal",
"startLine": {
"line": 2,
"offset": 4
},
"endLine": {
"line": 10,
"offset": 5
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "current package reference",
"filePath": "proj_1/services.bal",
"position": {
"line": 17,
"offset": 16
},
"response": {
"filePath": "proj_1/services.bal",
"startLine": {
"line": 12,
"offset": 4
},
"endLine": {
"line": 20,
"offset": 5
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public client class Client {

resource function get path(boolean flag) returns string {
do {
if flag {
return "path1";
} else {
return "path2";
}
}
}

remote function name(boolean flag) returns string {
do {
if flag {
return "name1";
} else {
return "name2";
}
}
}

}

0 comments on commit 717db29

Please sign in to comment.