Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…a-dev-tools into config-var-bug
  • Loading branch information
KavinduZoysa committed Jan 28, 2025
2 parents 492b086 + fea9c91 commit 6a53ed9
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,17 @@ private void genSourceFromMappingThroughElements(MappingElements mappingElements
String[] splits = substring.split("\\.");
int length = splits.length;
String lastSplit = splits[length - 1];
if (length == 1 && lastSplit.matches("^-?\\d+$")) {
if (length == 1 && lastSplit.matches("\\d+")) {
elements.add(mapping.expression());
return;
continue;
}
Map<String, Object> currentMapping = m;
String key = splits[0];
for (int i = 0; i < length; i++) {
String split = splits[i];
Object o = currentMapping.get(key);
if (o == null) {
if (!split.matches("^-?\\d+$")) {
if (!split.matches("\\d+")) {
if (i == length - 1) {
Object o1 = genExprFromMapping(mapping);
currentMapping.put(split, o1);
Expand All @@ -659,7 +659,9 @@ private void genSourceFromMappingThroughElements(MappingElements mappingElements
}
}
}
elements.add(m);
if (!m.isEmpty()) {
elements.add(m);
}
}

public String getSource(JsonElement mp, JsonElement fNode, String targetField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.gson.JsonArray;
import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.compiler.api.symbols.Qualifier;
import io.ballerina.compiler.api.symbols.Symbol;
import io.ballerina.compiler.api.symbols.SymbolKind;
import io.ballerina.compiler.api.symbols.VariableSymbol;
import io.ballerina.compiler.syntax.tree.ModulePartNode;
Expand Down Expand Up @@ -64,28 +65,35 @@ public JsonArray getVisibleVariableTypes() {
List<Category.Variable> moduleVariables = new ArrayList<>();
List<Category.Variable> configurableVariables = new ArrayList<>();
List<Category.Variable> localVariables = new ArrayList<>();
List<Category.Variable> parameters = new ArrayList<>();
List<Category> categories = Arrays.asList(
new Category(Category.MODULE_CATEGORY, moduleVariables),
new Category(Category.CONFIGURABLE_CATEGORY, configurableVariables),
new Category(Category.LOCAL_CATEGORY, localVariables)
new Category(Category.LOCAL_CATEGORY, localVariables),
new Category(Category.PARAMETER_CATEGORY, parameters)
);

semanticModel.visibleSymbols(document, position).stream()
.filter(symbol -> symbol.kind() == SymbolKind.VARIABLE)
.map(symbol -> (VariableSymbol) symbol)
.forEach(variableSymbol -> {
String name = variableSymbol.getName().orElse("");
Type type = Type.fromSemanticSymbol(variableSymbol);

if (variableSymbol.qualifiers().contains(Qualifier.CONFIGURABLE)) {
configurableVariables.add(new Category.Variable(name, type));
} else if (functionLineRange.isPresent() &&
isInFunctionRange(variableSymbol, functionLineRange.get())) {
localVariables.add(new Category.Variable(name, type));
} else {
moduleVariables.add(new Category.Variable(name, type));
}
});
List<Symbol> symbols = semanticModel.visibleSymbols(document, position);
for (Symbol symbol : symbols) {
if (symbol.kind() == SymbolKind.VARIABLE) {
VariableSymbol variableSymbol = (VariableSymbol) symbol;
String name = variableSymbol.getName().orElse("");
Type type = Type.fromSemanticSymbol(variableSymbol);

if (variableSymbol.qualifiers().contains(Qualifier.CONFIGURABLE)) {
configurableVariables.add(new Category.Variable(name, type));
} else if (functionLineRange.isPresent() &&
isInFunctionRange(variableSymbol, functionLineRange.get())) {
localVariables.add(new Category.Variable(name, type));
} else {
moduleVariables.add(new Category.Variable(name, type));
}
} else if (symbol.kind() == SymbolKind.PARAMETER) {
String name = symbol.getName().orElse("");
Type type = Type.fromSemanticSymbol(symbol);
parameters.add(new Category.Variable(name, type));
}
}

categories.forEach(category -> Collections.sort(category.types()));
return gson.toJsonTree(categories).getAsJsonArray();
Expand Down Expand Up @@ -122,6 +130,7 @@ private record Category(String name, List<Variable> types) {
public static final String MODULE_CATEGORY = "Module Variables";
public static final String CONFIGURABLE_CATEGORY = "Configurable Variables";
public static final String LOCAL_CATEGORY = "Local Variables";
public static final String PARAMETER_CATEGORY = "Parameters";

public record Variable(String name, Type type) implements Comparable<Variable> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def pullBallerinaModule(String packageName) {
}
}

//test.dependsOn pullBallerinaModule('ballerinax/redis')
//test.dependsOn pullBallerinaModule('ballerinax/trigger.salesforce')
//test.dependsOn pullBallerinaModule('ballerinax/github')
//test.dependsOn pullBallerinaModule('ballerinax/snowflake')
//test.dependsOn pullBallerinaModule('ballerinax/docusign.dsadmin')
test.dependsOn pullBallerinaModule('ballerinax/redis')
test.dependsOn pullBallerinaModule('ballerinax/trigger.salesforce')
test.dependsOn pullBallerinaModule('ballerinax/github')
test.dependsOn pullBallerinaModule('ballerinax/snowflake')
test.dependsOn pullBallerinaModule('ballerinax/docusign.dsadmin')

test {
dependsOn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ protected Object[] getConfigsList() {
{Path.of("variable12.json")},
{Path.of("variable13.json")},
{Path.of("variable14.json")},
{Path.of("variable15.json")},
{Path.of("variable16.json")},
{Path.of("variable17.json")},
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"source": "variable14.bal",
"description": "Sample diagram node",
"diagram": {
"id": "31",
"metadata": {
"label": "Variable",
"description": "New variable with type"
},
"codedata": {
"node": "VARIABLE",
"lineRange": {
"startLine": {
"line": 16,
"offset": 36
},
"endLine": {
"line": 16,
"offset": 36
}
}
},
"returning": false,
"properties": {
"variable": {
"metadata": {
"label": "Name",
"description": "Name of the variable"
},
"valueType": "IDENTIFIER",
"value": "var1",
"optional": false,
"editable": true,
"advanced": false
},
"type": {
"metadata": {
"label": "Type",
"description": "Type of the variable"
},
"valueType": "TYPE",
"value": "Students",
"placeholder": "var",
"optional": false,
"editable": true,
"advanced": false
},
"expression": {
"metadata": {
"label": "Expression",
"description": "Initialize with value"
},
"valueType": "EXPRESSION",
"value": "{names:[\"1\",\"2\", \"4\"]}",
"optional": true,
"editable": true,
"advanced": false
}
},
"flags": 0
},
"propertyKey": "expression",
"position": {
"line": 17,
"offset": 30
},
"mappings": [
{
"output": "var1.names",
"inputs": [],
"expression": "[\"1\", \"2\"]",
"diagnostics": [],
"elements": [
{
"mappings": [
{
"output": "var1.names.0",
"inputs": [],
"expression": "\"1\"",
"diagnostics": [],
"elements": []
},
{
"output": "var1.names.1",
"inputs": [],
"expression": "\"2\"",
"diagnostics": [],
"elements": []
}
]
}
]
}
],
"output": "{names:[\"1\",\"2\"]}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"source": "variable15.bal",
"description": "Sample diagram node",
"diagram": {
"id": "31",
"metadata": {
"label": "Variable",
"description": "New variable with type"
},
"codedata": {
"node": "VARIABLE",
"lineRange": {
"startLine": {
"line": 16,
"offset": 36
},
"endLine": {
"line": 16,
"offset": 36
}
}
},
"returning": false,
"properties": {
"variable": {
"metadata": {
"label": "Name",
"description": "Name of the variable"
},
"valueType": "IDENTIFIER",
"value": "var1",
"optional": false,
"editable": true,
"advanced": false
},
"type": {
"metadata": {
"label": "Type",
"description": "Type of the variable"
},
"valueType": "TYPE",
"value": "Students",
"placeholder": "var",
"optional": false,
"editable": true,
"advanced": false
},
"expression": {
"metadata": {
"label": "Expression",
"description": "Initialize with value"
},
"valueType": "EXPRESSION",
"value": "{names:[[\"1\", \"6\"],[\"10\", \"60\"],[\"10\", \"60\", \"70\"]]}",
"optional": true,
"editable": true,
"advanced": false
}
},
"flags": 0
},
"propertyKey": "expression",
"position": {
"line": 17,
"offset": 30
},
"mappings": [
{
"output": "var1.names",
"inputs": [],
"expression": "[[\"1\", \"6\"], [\"10\", \"60\"], [\"10\", \"61\"]]",
"diagnostics": [],
"elements": [
{
"mappings": [
{
"output": "var1.names.0",
"inputs": [],
"expression": "[\"1\", \"6\"]",
"diagnostics": [],
"elements": [
{
"mappings": [
{
"output": "var1.names.0.0",
"inputs": [],
"expression": "\"1\"",
"diagnostics": [],
"elements": []
},
{
"output": "var1.names.0.1",
"inputs": [],
"expression": "\"6\"",
"diagnostics": [],
"elements": []
}
]
}
]
},
{
"output": "var1.names.1",
"inputs": [],
"expression": "[\"10\", \"60\"]",
"diagnostics": [],
"elements": [
{
"mappings": [
{
"output": "var1.names.1.0",
"inputs": [],
"expression": "\"10\"",
"diagnostics": [],
"elements": []
},
{
"output": "var1.names.1.1",
"inputs": [],
"expression": "\"60\"",
"diagnostics": [],
"elements": []
}
]
}
]
},
{
"output": "var1.names.2",
"inputs": [],
"expression": "[\"10\", \"61\"]",
"diagnostics": [],
"elements": [
{
"mappings": [
{
"output": "var1.names.2.0",
"inputs": [],
"expression": "\"10\"",
"diagnostics": [],
"elements": []
},
{
"output": "var1.names.2.1",
"inputs": [],
"expression": "\"61\"",
"diagnostics": [],
"elements": []
}
]
}
]
}
]
}
]
}
],
"output": "{names:[[\"1\", \"6\"],[\"10\", \"60\"],[\"10\", \"61\"]]}"
}
Loading

0 comments on commit 6a53ed9

Please sign in to comment.