Skip to content

Commit

Permalink
Merge pull request #42809 from KavinduZoysa/fix-issue-42304
Browse files Browse the repository at this point in the history
Support update documentation CA for included record params
  • Loading branch information
KavinduZoysa authored Aug 2, 2024
2 parents c83ef26 + dbfdf45 commit e8ae25b
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.ballerina.compiler.syntax.tree.EnumDeclarationNode;
import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode;
import io.ballerina.compiler.syntax.tree.FunctionSignatureNode;
import io.ballerina.compiler.syntax.tree.IncludedRecordParameterNode;
import io.ballerina.compiler.syntax.tree.MetadataNode;
import io.ballerina.compiler.syntax.tree.MethodDeclarationNode;
import io.ballerina.compiler.syntax.tree.ModuleMemberDeclarationNode;
Expand Down Expand Up @@ -335,14 +336,13 @@ private static DocAttachmentInfo getFunctionNodeDocumentation(FunctionSignatureN
});
}
signatureNode.parameters().forEach(param -> {
Optional<Token> paramName = Optional.empty();
if (param.kind() == SyntaxKind.REQUIRED_PARAM) {
paramName = ((RequiredParameterNode) param).paramName();
} else if (param.kind() == SyntaxKind.DEFAULTABLE_PARAM) {
paramName = ((DefaultableParameterNode) param).paramName();
} else if (param.kind() == SyntaxKind.REST_PARAM) {
paramName = ((RestParameterNode) param).paramName();
}
Optional<Token> paramName = switch (param.kind()) {
case REQUIRED_PARAM -> ((RequiredParameterNode) param).paramName();
case DEFAULTABLE_PARAM -> ((DefaultableParameterNode) param).paramName();
case REST_PARAM -> ((RestParameterNode) param).paramName();
case INCLUDED_RECORD_PARAM -> ((IncludedRecordParameterNode) param).paramName();
default -> Optional.empty();
};
paramName.ifPresent(token -> parameters.put(token.text(), "parameter description"));
});
String returnDesc = signatureNode.returnTypeDesc().isPresent() ? "return value description" : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public Object[][] addDocDataProvider() {
{"updateDocumentationConfig3.json"},
{"updateDocumentationConfig4.json"},
{"updateDocumentationConfig5.json"},
{"updateDocumentationConfig6.json"},
{"updateDocumentationConfig7.json"},
{"updateDocumentationConfig8.json"},
{"updateDocumentationWithDeprecatedConfig1.json"},
{"updateDocumentationWithDeprecatedConfig2.json"},
{"updateDocumentationWithDeprecatedConfig3.json"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"arguments": {
"node.range": {
"start": {
"line": 5,
"character": 0
},
"end": {
"line": 11,
"character": 1
}
}
},
"source": "updateDocumentationSource6.bal",
"expected": {
"result": {
"edit": {
"documentChanges": [
{
"edits": [
{
"range": {
"start": {
"line": 5,
"character": 0
},
"end": {
"line": 8,
"character": 34
}
},
"newText": "# Description.\n#\n# + id - parameter description \n# + value - parameter description \n# + config - parameter description"
}
]
}
]
}
},
"jsonrpc": "2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"arguments": {
"node.range": {
"start": {
"line": 6,
"character": 4
},
"end": {
"line": 12,
"character": 5
}
}
},
"source": "updateDocumentationSource7.bal",
"expected": {
"result": {
"edit": {
"documentChanges": [
{
"edits": [
{
"range": {
"start": {
"line": 6,
"character": 4
},
"end": {
"line": 9,
"character": 38
}
},
"newText": "# Description.\n #\n # + id - parameter description \n # + value - parameter description \n # + config - parameter description"
}
]
}
]
}
},
"jsonrpc": "2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"arguments": {
"node.range": {
"start": {
"line": 12,
"character": 3
},
"end": {
"line": 18,
"character": 4
}
}
},
"source": "updateDocumentationSource8.bal",
"expected": {
"result": {
"edit": {
"documentChanges": [
{
"edits": [
{
"range": {
"start": {
"line": 12,
"character": 3
},
"end": {
"line": 15,
"character": 40
}
},
"newText": "# Description.\n #\n # + val - parameter description \n # + args - parameter description\n # + return - return value description"
}
]
}
]
}
},
"jsonrpc": "2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type ParamConfig record {|
string timeEntry;
string msg;
|};

# Description.
#
# + id - parameter description
# + config - parameter description
function logMsg(int id, int value, *ParamConfig config) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type ParamConfig record {|
string timeEntry;
string msg;
|};

class Log {
# Description.
#
# + id - parameter description
# + config - parameter description
function logMsg(int id, int value, *ParamConfig config) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type Args record {|
decimal x;
decimal y;
|};

type Response record {|
decimal result;
|};

listener http:Listener ln = new (9090);

service /calc on ln {
# Description.
#
# + args - parameter description
# + return - return value description
resource function post add(int val, *Args args) returns Response {
return {result: args.x + args.y};
}
}

0 comments on commit e8ae25b

Please sign in to comment.