Skip to content

Commit

Permalink
Add missing fields in inferred property
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Mar 5, 2025
1 parent 83f0557 commit 3d2f4fd
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.ballerinalang.langserver.commons.workspace.WorkspaceManager;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

/**
* Abstract base class for function-like builders (functions, methods, resource actions).
Expand Down Expand Up @@ -132,10 +134,9 @@ public static void buildInferredTypeProperty(NodeBuilder nodeBuilder, ParameterD
.stepOut()
.value(value)
.placeholder(paramData.defaultValue())
.type(Property.ValueType.TYPE)
.typeConstraint(paramData.type())
.typeMembers(paramData.typeMembers())
.editable()
.defaultable(paramData.optional())
.stepOut()
.addProperty(unescapedParamName);
}
Expand All @@ -144,14 +145,16 @@ protected void setParameterProperties(FunctionData function) {
boolean hasOnlyRestParams = function.parameters().size() == 1;

// Build the inferred type property at the top if exists
if (function.inferredReturnType()) {
function.parameters().values().stream()
.filter(param -> param.kind().equals(ParameterData.Kind.PARAM_FOR_TYPE_INFER))
.findFirst()
.ifPresent(param -> buildInferredTypeProperty(this, param, null));
}
Map<String, ParameterData> paramMap = new HashMap<>();
function.parameters().forEach((key, paramData) -> {
if (paramData.kind() != ParameterData.Kind.PARAM_FOR_TYPE_INFER) {
paramMap.put(key, paramData);
return;
}
buildInferredTypeProperty(this, paramData, null);
});

for (ParameterData paramResult : function.parameters().values()) {
for (ParameterData paramResult : paramMap.values()) {
if (paramResult.kind().equals(ParameterData.Kind.INCLUDED_RECORD)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
"typeMembers": [
{
"type": "ConnectionPool",
"packageInfo": "ballerina:sql:1.15.0",
"packageInfo": "ballerina:sql:1.14.0",
"kind": "RECORD_TYPE",
"selected": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
"typeMembers": [
{
"type": "ConnectionPool",
"packageInfo": "ballerina:sql:1.15.0",
"packageInfo": "ballerina:sql:1.14.0",
"kind": "RECORD_TYPE",
"selected": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
},
"returning": false,
"properties": {
"t": {
"metadata": {
"label": "t",
"description": "Target type"
},
"valueType": "TYPE",
"valueTypeConstraint": "anydata",
"placeholder": "anydata",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "t"
}
},
"s": {
"metadata": {
"label": "s",
Expand Down Expand Up @@ -78,23 +94,6 @@
}
]
},
"t": {
"metadata": {
"label": "t",
"description": "Target type"
},
"valueType": "TYPE",
"valueTypeConstraint": "anydata",
"placeholder": "anydata",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "t"
},
"typeMembers": []
},
"type": {
"metadata": {
"label": "Variable Type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@
"editable": false,
"advanced": false
},
"targetType": {
"metadata": {
"label": "targetType",
"description": "HTTP response, `anydata` or stream of HTTP SSE, which is expected to be returned after data binding"
},
"valueType": "TYPE",
"valueTypeConstraint": "http:Response|anydata|stream<http:SseEvent, error?>",
"placeholder": "http:Response|anydata|stream<http:SseEvent, error?>",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "targetType"
}
},
"path": {
"metadata": {
"label": "path",
Expand Down Expand Up @@ -99,23 +115,6 @@
}
]
},
"targetType": {
"metadata": {
"label": "targetType",
"description": "HTTP response, `anydata` or stream of HTTP SSE, which is expected to be returned after data binding"
},
"valueType": "TYPE",
"valueTypeConstraint": "http:Response|anydata|stream<http:SseEvent, error?>",
"placeholder": "http:Response|anydata|stream<http:SseEvent, error?>",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "targetType"
},
"typeMembers": []
},
"type": {
"metadata": {
"label": "Variable Type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@
"editable": false,
"advanced": false
},
"targetType": {
"metadata": {
"label": "targetType",
"description": "HTTP response, `anydata` or stream of HTTP SSE, which is expected to be returned after data binding"
},
"valueType": "TYPE",
"valueTypeConstraint": "http:Response|anydata|stream<http:SseEvent, error?>",
"placeholder": "http:Response|anydata|stream<http:SseEvent, error?>",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "targetType"
}
},
"path": {
"metadata": {
"label": "path",
Expand All @@ -69,30 +85,6 @@
}
]
},
"message": {
"metadata": {
"label": "message",
"description": "An HTTP outbound request or any allowed payload"
},
"valueType": "EXPRESSION",
"valueTypeConstraint": "http:RequestMessage",
"placeholder": "{}",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "REQUIRED",
"originalName": "message"
},
"typeMembers": [
{
"type": "RequestMessage",
"packageInfo": "ballerina:http:2.12.2",
"kind": "OTHER",
"selected": false
}
]
},
"headers": {
"metadata": {
"label": "headers",
Expand Down Expand Up @@ -153,22 +145,29 @@
}
]
},
"targetType": {
"message": {
"metadata": {
"label": "targetType",
"description": "HTTP response, `anydata` or stream of HTTP SSE, which is expected to be returned after data binding"
"label": "message",
"description": "An HTTP outbound request or any allowed payload"
},
"valueType": "TYPE",
"valueTypeConstraint": "http:Response|anydata|stream<http:SseEvent, error?>",
"placeholder": "http:Response|anydata|stream<http:SseEvent, error?>",
"valueType": "EXPRESSION",
"valueTypeConstraint": "http:RequestMessage",
"placeholder": "{}",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "targetType"
"kind": "REQUIRED",
"originalName": "message"
},
"typeMembers": []
"typeMembers": [
{
"type": "RequestMessage",
"packageInfo": "ballerina:http:2.12.2",
"kind": "OTHER",
"selected": false
}
]
},
"type": {
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "rowType"
},
"typeMembers": []
}
},
"sqlQuery": {
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "returnType"
},
"typeMembers": []
}
},
"sqlQuery": {
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@
"editable": false,
"advanced": false
},
"rowType": {
"metadata": {
"label": "rowType",
"description": "The `typedesc` of the record to which the result needs to be returned"
},
"valueType": "TYPE",
"valueTypeConstraint": "record {|anydata...;|}",
"placeholder": "record {|anydata...;|}",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "rowType"
}
},
"sqlQuery": {
"metadata": {
"label": "sqlQuery",
Expand All @@ -70,23 +86,6 @@
}
]
},
"rowType": {
"metadata": {
"label": "rowType",
"description": "The `typedesc` of the record to which the result needs to be returned"
},
"valueType": "TYPE",
"valueTypeConstraint": "record {|anydata...;|}",
"placeholder": "record {|anydata...;|}",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "rowType"
},
"typeMembers": []
},
"type": {
"metadata": {
"label": "Variable Type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@
"originalName": "/path/to/subdirectory"
}
},
"targetType": {
"metadata": {
"label": "targetType",
"description": "HTTP response, `anydata` or stream of HTTP SSE, which is expected to be returned after data binding"
},
"valueType": "TYPE",
"valueTypeConstraint": "http:Response|anydata|stream<http:SseEvent, error?>",
"placeholder": "http:Response|anydata|stream<http:SseEvent, error?>",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "targetType"
}
},
"headers": {
"metadata": {
"label": "headers",
Expand Down Expand Up @@ -88,23 +104,6 @@
}
]
},
"targetType": {
"metadata": {
"label": "targetType",
"description": "HTTP response, `anydata` or stream of HTTP SSE, which is expected to be returned after data binding"
},
"valueType": "TYPE",
"valueTypeConstraint": "http:Response|anydata|stream<http:SseEvent, error?>",
"placeholder": "http:Response|anydata|stream<http:SseEvent, error?>",
"optional": false,
"editable": true,
"advanced": false,
"codedata": {
"kind": "PARAM_FOR_TYPE_INFER",
"originalName": "targetType"
},
"typeMembers": []
},
"additionalValues": {
"metadata": {
"label": "Additional Values",
Expand Down

0 comments on commit 3d2f4fd

Please sign in to comment.