Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ public void visit(FunctionDefinitionNode functionDefinitionNode) {
} else {
kind = FunctionKind.RESOURCE;
}
} else if (hasQualifier(functionDefinitionNode.qualifierList(), SyntaxKind.REMOTE_KEYWORD)) {
} else if (functionDefinitionNode.qualifierList().stream()
.anyMatch(qualifier -> qualifier.kind() == SyntaxKind.REMOTE_KEYWORD)) {
kind = FunctionKind.REMOTE_FUNCTION;
} else {
kind = FunctionKind.FUNCTION;
Expand Down Expand Up @@ -1047,16 +1048,20 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
List<String> restArgs = new ArrayList<>();
for (int i = 0; i < paramsList.size(); i++) {
ParameterSymbol parameterSymbol = paramsList.get(i);
String escapedParamName = parameterSymbol.getName().get();
Optional<String> nameOptional = parameterSymbol.getName();
if (nameOptional.isEmpty()) {
continue;
}
String escapedParamName = nameOptional.get();
ParameterData paramResult = funcParamMap.get(escapedParamName);
if (paramResult == null) {
escapedParamName = CommonUtil.escapeReservedKeyword(parameterSymbol.getName().get());
escapedParamName = CommonUtil.escapeReservedKeyword(nameOptional.get());
}
paramResult = funcParamMap.get(escapedParamName);
Node paramValue = i < argCount ? positionalArgs.poll()
: namedArgValueMap.get(paramResult.name());

funcParamMap.remove(parameterSymbol.getName().get());
funcParamMap.remove(nameOptional.get());
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder =
nodeBuilder.properties().custom();
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
Expand Down Expand Up @@ -1088,13 +1093,22 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
}
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder =
nodeBuilder.properties().custom();
String escapedParamName = restParamSymbol.getName().get();
Optional<String> restNameOptional = restParamSymbol.getName();
if (restNameOptional.isEmpty()) {
return;
}
String escapedParamName = restNameOptional.get();
ParameterData restParamResult = funcParamMap.get(escapedParamName);
if (restParamResult == null) {
restParamResult = funcParamMap.get(CommonUtil.escapeReservedKeyword(
restParamSymbol.getName().get()));
Optional<String> restParamNameOptional = restParamSymbol.getName();
if (restParamNameOptional.isPresent()) {
restParamResult = funcParamMap.get(CommonUtil.escapeReservedKeyword(
restParamNameOptional.get()));
}
}
funcParamMap.remove(restParamSymbol.getName().get());
Optional<String> restParamNameForRemoval = restParamSymbol.getName();
restParamNameForRemoval.ifPresent(funcParamMap::remove);
assert restParamResult != null;
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(restParamResult.name());
buildPropertyType(customPropBuilder, restParamResult);
customPropBuilder
Expand Down Expand Up @@ -1128,7 +1142,11 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
final List<LinkedHashMap<String, String>> includedRecordRestArgs = new ArrayList<>();
for (int i = 0; i < paramsList.size(); i++) {
ParameterSymbol parameterSymbol = paramsList.get(i);
String escapedParamName = parameterSymbol.getName().get();
Optional<String> paramNameOptional = parameterSymbol.getName();
if (paramNameOptional.isEmpty()) {
continue;
}
String escapedParamName = paramNameOptional.get();
if (!funcParamMap.containsKey(escapedParamName)) {
escapedParamName = CommonUtil.escapeReservedKeyword(escapedParamName);
if (!funcParamMap.containsKey(escapedParamName)) {
Expand Down Expand Up @@ -1368,25 +1386,40 @@ private void buildPropertyType(Property.Builder<?> builder, ParameterData paramD
builder.type(Property.ValueType.EXPRESSION_SET);
} else if (kind == ParameterData.Kind.INCLUDED_RECORD_REST) {
builder.type(Property.ValueType.MAPPING_EXPRESSION_SET);
} else if (isSubTypeOfRawTemplate(paramData.typeSymbol())) {
String typeSignature = CommonUtils.getTypeSignature(paramData.typeSymbol(), moduleInfo);
if (AiUtils.AI_PROMPT_TYPE.equals(typeSignature)) {
boolean isPromptSelected = value != null && value.kind() == SyntaxKind.RAW_TEMPLATE_EXPRESSION;
} else {
String ballerinaType = CommonUtils.getTypeSignature(paramData.typeSymbol(), moduleInfo);
if (ballerinaType != null && ballerinaType.contains("ParameterizedQuery")) {
// Handle SQL query parameters with SQL_QUERY as primary option
builder.type()
.fieldType(Property.ValueType.PROMPT)
.ballerinaType(AiUtils.AI_PROMPT_TYPE)
.selected(isPromptSelected)
.fieldType(Property.ValueType.SQL_QUERY)
.ballerinaType(ballerinaType)
.selected(true)
.stepOut();
builder.type()
.fieldType(Property.ValueType.EXPRESSION)
.ballerinaType(typeSignature)
.selected(!isPromptSelected)
.ballerinaType(ballerinaType)
.selected(false)
.stepOut();
} else if (isSubTypeOfRawTemplate(paramData.typeSymbol())) {
String typeSignature = CommonUtils.getTypeSignature(paramData.typeSymbol(), moduleInfo);
if (AiUtils.AI_PROMPT_TYPE.equals(typeSignature)) {
boolean isPromptSelected = value != null && value.kind() == SyntaxKind.RAW_TEMPLATE_EXPRESSION;
builder.type()
.fieldType(Property.ValueType.PROMPT)
.ballerinaType(AiUtils.AI_PROMPT_TYPE)
.selected(isPromptSelected)
.stepOut();
builder.type()
.fieldType(Property.ValueType.EXPRESSION)
.ballerinaType(typeSignature)
.selected(!isPromptSelected)
.stepOut();
} else {
builder.type(Property.ValueType.RAW_TEMPLATE);
}
} else {
builder.type(Property.ValueType.RAW_TEMPLATE);
builder.typeWithExpression(paramData.typeSymbol(), moduleInfo, value, semanticModel, builder);
}
} else {
builder.typeWithExpression(paramData.typeSymbol(), moduleInfo, value, semanticModel, builder);
}
}

Expand Down Expand Up @@ -2267,9 +2300,14 @@ public void visit(RollbackStatementNode rollbackStatementNode) {

@Override
public void visit(RetryStatementNode retryStatementNode) {
int retryCount = retryStatementNode.arguments().isEmpty() ? 3 :
Integer.parseInt(retryStatementNode.arguments()
.map(arg -> arg.arguments().get(0)).get().toString());
int retryCount;
if (retryStatementNode.arguments().isEmpty()) {
retryCount = 3;
} else {
Optional<Node> argumentOptional = retryStatementNode.arguments()
.map(arg -> arg.arguments().get(0));
retryCount = argumentOptional.map(node -> Integer.parseInt(node.toString())).orElse(3);
}

StatementNode statementNode = retryStatementNode.retryBody();
if (statementNode.kind() == SyntaxKind.BLOCK_STATEMENT) {
Expand Down Expand Up @@ -2718,8 +2756,12 @@ private boolean isSubTypeOfRawTemplate(TypeSymbol typeSymbol) {

// TODO: Once https://github.com/ballerina-platform/ballerina-lang/pull/43871 is merged,
// we can use `typeSymbol.subtypeOf(semanticModel.types().RAW_TEMPLATE)` to check the subtyping
TypeDefinitionSymbol rawTypeDefSymbol = (TypeDefinitionSymbol)
semanticModel.types().getTypeByName(BALLERINA_ORG_NAME, "lang.object", "0.0.0", "RawTemplate").get();
Optional<Symbol> rawSymbolOptional = semanticModel.types()
.getTypeByName(BALLERINA_ORG_NAME, "lang.object", "0.0.0", "RawTemplate");
if (rawSymbolOptional.isEmpty()) {
return false;
}
TypeDefinitionSymbol rawTypeDefSymbol = (TypeDefinitionSymbol) rawSymbolOptional.get();

TypeSymbol rawTemplateTypeDesc = rawTypeDefSymbol.typeDescriptor();
return typeSymbol.subtypeOf(rawTemplateTypeDesc);
Expand Down Expand Up @@ -2768,9 +2810,6 @@ private static String getPathString(NodeList<Node> nodes) {
.collect(Collectors.joining());
}

private static boolean hasQualifier(NodeList<Token> qualifierList, SyntaxKind kind) {
return qualifierList.stream().anyMatch(qualifier -> qualifier.kind() == kind);
}

private boolean isAgent(ServiceDeclarationNode serviceDeclarationNode) {
SeparatedNodeList<ExpressionNode> expressions = serviceDeclarationNode.expressions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static DiagnosticsRequest from(ExpressionEditorContext context) {

Property.ValueType fieldType = property.propertyType().fieldType();
return switch (fieldType) {
case EXPRESSION -> new ExpressionDiagnosticsRequest(context);
case EXPRESSION, SQL_QUERY -> new ExpressionDiagnosticsRequest(context);
case LV_EXPRESSION -> new LvExpressionDiagnosticRequest(context);
case ACTION_OR_EXPRESSION -> new ActionOrExpressionDiagnosticsRequest(context);
case IDENTIFIER -> new IdentifierDiagnosticsRequest(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ public enum ValueType {
ACTION_TYPE,
DATA_MAPPING_EXPRESSION,
RECORD_MAP_EXPRESSION,
PROMPT
PROMPT,
SQL_QUERY
}

public static class Builder<T> extends FacetedBuilder<T> implements DiagnosticHandler.DiagnosticCapable {
Expand Down Expand Up @@ -705,6 +706,12 @@ private String getSelectedType(Node value, SemanticModel semanticModel) {
}

private boolean handlePrimitiveType(TypeSymbol typeSymbol, String ballerinaType) {
// Check for SQL query types first
if ("sql:ParameterizedQuery".equals(ballerinaType)) {
type().fieldType(ValueType.SQL_QUERY).ballerinaType(ballerinaType).selected(true).stepOut();
return true;
}

TypeSymbol rawType = CommonUtil.getRawType(typeSymbol);
switch (rawType.typeKind()) {
case INT, INT_SIGNED8, INT_UNSIGNED8, INT_SIGNED16, INT_UNSIGNED16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
},
"types": [
{
"fieldType": "EXPRESSION",
"fieldType": "SQL_QUERY",
"ballerinaType": "sql:ParameterizedQuery",
"selected": true
},
{
"fieldType": "EXPRESSION",
"ballerinaType": "sql:ParameterizedQuery",
"selected": false
}
],
"value": "object {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
},
"types": [
{
"fieldType": "SQL_QUERY",
"ballerinaType": "sql:ParameterizedQuery",
"fieldType": "EXPRESSION"
"selected": true
},
{
"ballerinaType": "sql:ParameterizedQuery",
"fieldType": "EXPRESSION",
"selected": false
}
],
"placeholder": "``",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@
},
"types": [
{
"fieldType": "RAW_TEMPLATE",
"fieldType": "SQL_QUERY",
"ballerinaType": "sql:ParameterizedQuery",
"selected": true
},
{
"fieldType": "EXPRESSION",
"ballerinaType": "sql:ParameterizedQuery",
"selected": false
}
],
Expand Down Expand Up @@ -243,7 +249,13 @@
},
"types": [
{
"fieldType": "RAW_TEMPLATE",
"fieldType": "SQL_QUERY",
"ballerinaType": "sql:ParameterizedQuery",
"selected": true
},
{
"fieldType": "EXPRESSION",
"ballerinaType": "sql:ParameterizedQuery",
"selected": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@
},
"types": [
{
"fieldType": "RAW_TEMPLATE",
"fieldType": "SQL_QUERY",
"ballerinaType": "sql:ParameterizedQuery",
"selected": true
},
{
"fieldType": "EXPRESSION",
"ballerinaType": "sql:ParameterizedQuery",
"selected": false
}
],
Expand Down
Loading
Loading