diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/DocumentComponentTransformer.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/DocumentComponentTransformer.java index 51dcefa19899..22c075f78205 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/DocumentComponentTransformer.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/DocumentComponentTransformer.java @@ -26,6 +26,7 @@ import io.ballerina.compiler.syntax.tree.NonTerminalNode; import io.ballerina.compiler.syntax.tree.ServiceDeclarationNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.compiler.syntax.tree.Token; import io.ballerina.compiler.syntax.tree.TypeDefinitionNode; import io.ballerina.tools.text.LineRange; @@ -63,6 +64,11 @@ public Optional transformSyntaxNode(Node node) { @Override public Optional transform(FunctionDefinitionNode functionDefinitionNode) { + if (functionDefinitionNode.functionName().text().equals(PackageServiceConstants.MAIN_FUNCTION)) { + return Optional.of(new MapperObject(PackageServiceConstants.AUTOMATIONS, + createDataObject(PackageServiceConstants.MAIN_FUNCTION, functionDefinitionNode))); + } + return Optional.of(new MapperObject(PackageServiceConstants.FUNCTIONS, createDataObject(functionDefinitionNode.functionName().text(), functionDefinitionNode))); } @@ -80,8 +86,12 @@ public Optional transform(ServiceDeclarationNode serviceDeclaratio DataObject dataObject = createDataObject(name, serviceDeclarationNode); serviceDeclarationNode.members().forEach(member -> { if (member.kind() == SyntaxKind.RESOURCE_ACCESSOR_DEFINITION) { - dataObject.addResource(createDataObject(((FunctionDefinitionNode) member).functionName().text(), - member)); + FunctionDefinitionNode functionDefinitionNode = (FunctionDefinitionNode) member; + String resourceName = functionDefinitionNode.functionName().text() + "-" + + functionDefinitionNode.relativeResourcePath().stream() + .map(Node::toSourceCode) + .collect(Collectors.joining("")); + dataObject.addResource(createDataObject(resourceName, member)); } }); return Optional.of(new MapperObject(PackageServiceConstants.SERVICES, dataObject)); @@ -115,9 +125,17 @@ public Optional transform(TypeDefinitionNode typeDefinitionNode) { @Override public Optional transform(ModuleVariableDeclarationNode moduleVariableDeclarationNode) { + Optional isConfigurable = moduleVariableDeclarationNode.qualifiers().stream() + .filter(qualifier -> qualifier.kind() == SyntaxKind.CONFIGURABLE_KEYWORD) + .findFirst(); + if (isConfigurable.isPresent()) { + return Optional.of(new MapperObject(PackageServiceConstants.CONFIGURABLE_VARIABLES, + createDataObject(moduleVariableDeclarationNode.typedBindingPattern().bindingPattern().toString(), + moduleVariableDeclarationNode))); + } return Optional.of(new MapperObject(PackageServiceConstants.MODULE_LEVEL_VARIABLE, createDataObject(moduleVariableDeclarationNode.typedBindingPattern().bindingPattern().toString(), - moduleVariableDeclarationNode))); + moduleVariableDeclarationNode))); } @Override diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/ModuleObject.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/ModuleObject.java index 4b7fedfdd0c1..faaf15a9e1e7 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/ModuleObject.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/ModuleObject.java @@ -32,6 +32,8 @@ public class ModuleObject { private final List enums = new ArrayList<>(); private final List listeners = new ArrayList<>(); private final List moduleVariables = new ArrayList<>(); + private final List configurableVariables = new ArrayList<>(); + private final List automations = new ArrayList<>(); private String name; @@ -103,6 +105,12 @@ protected void addDataObject(MapperObject mapperObject) { case PackageServiceConstants.MODULE_LEVEL_VARIABLE: this.moduleVariables.add(mapperObject.getDataObject()); break; + case PackageServiceConstants.CONFIGURABLE_VARIABLES: + this.configurableVariables.add(mapperObject.getDataObject()); + break; + case PackageServiceConstants.AUTOMATIONS: + this.automations.add(mapperObject.getDataObject()); + break; default: break; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageServiceConstants.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageServiceConstants.java index 292b7d7fb505..780c62f8100a 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageServiceConstants.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageServiceConstants.java @@ -23,6 +23,7 @@ public class PackageServiceConstants { protected static final String CAPABILITY_NAME = "ballerinaPackage"; + protected static final String MAIN_FUNCTION = "main"; protected static final String NAME = "name"; protected static final String FILE_PATH = "filePath"; protected static final String START_LINE = "startLine"; @@ -41,4 +42,6 @@ public class PackageServiceConstants { protected static final String CLASSES = "classes"; protected static final String LISTENERS = "listeners"; protected static final String MODULE_LEVEL_VARIABLE = "moduleVariables"; + protected static final String CONFIGURABLE_VARIABLES = "configurableVariables"; + protected static final String AUTOMATIONS = "automations"; }