Skip to content

Commit

Permalink
Merge pull request #42800 from KavinduZoysa/fix-issue-42309
Browse files Browse the repository at this point in the history
Support Document this CA for module-type-def
  • Loading branch information
Nuvindu authored Sep 6, 2024
2 parents f783647 + 207d34e commit 54a7ef1
Show file tree
Hide file tree
Showing 23 changed files with 643 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,7 @@ public void visit(FunctionDefinitionNode node) {
@Override
public void visit(TypeDefinitionNode node) {
checkAndSetCodeActionNode(node);

// If cursor was outside object/record type desc, we have to manually check for the type
Node typeDescriptor = node.typeDescriptor();
if (typeDescriptor.kind() == SyntaxKind.RECORD_TYPE_DESC) {
checkAndSetSyntaxKind(typeDescriptor.kind());
} else if (typeDescriptor.kind() == SyntaxKind.OBJECT_TYPE_DESC) {
checkAndSetSyntaxKind(typeDescriptor.kind());
}
checkAndSetSyntaxKind(node.typeDescriptor().kind());

Optional<Token> qualifier = node.visibilityQualifier();
int startOffset = qualifier.isEmpty() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,39 @@ public List<SyntaxKind> getSyntaxKinds() {
SyntaxKind.ANNOTATION_DECLARATION,
SyntaxKind.MODULE_VAR_DECL,
SyntaxKind.ENUM_DECLARATION,
SyntaxKind.CONST_DECLARATION);
SyntaxKind.CONST_DECLARATION,
SyntaxKind.UNION_TYPE_DESC,
SyntaxKind.NIL_TYPE_DESC,
SyntaxKind.ARRAY_TYPE_DESC,
SyntaxKind.INT_TYPE_DESC,
SyntaxKind.BYTE_TYPE_DESC,
SyntaxKind.FLOAT_TYPE_DESC,
SyntaxKind.DECIMAL_TYPE_DESC,
SyntaxKind.STRING_TYPE_DESC,
SyntaxKind.BOOLEAN_TYPE_DESC,
SyntaxKind.XML_TYPE_DESC,
SyntaxKind.JSON_TYPE_DESC,
SyntaxKind.HANDLE_TYPE_DESC,
SyntaxKind.ANY_TYPE_DESC,
SyntaxKind.ANYDATA_TYPE_DESC,
SyntaxKind.NEVER_TYPE_DESC,
SyntaxKind.MAP_TYPE_DESC,
SyntaxKind.ERROR_TYPE_DESC,
SyntaxKind.STREAM_TYPE_DESC,
SyntaxKind.TABLE_TYPE_DESC,
SyntaxKind.FUNCTION_TYPE_DESC,
SyntaxKind.TUPLE_TYPE_DESC,
SyntaxKind.READONLY_TYPE_DESC,
SyntaxKind.FUTURE_TYPE_DESC,
SyntaxKind.SINGLETON_TYPE_DESC,
SyntaxKind.INTERSECTION_TYPE_DESC,
SyntaxKind.QUALIFIED_NAME_REFERENCE,
SyntaxKind.SIMPLE_NAME_REFERENCE,
SyntaxKind.TYPEDESC_TYPE_DESC,
SyntaxKind.DISTINCT_TYPE_DESC,
SyntaxKind.OPTIONAL_TYPE_DESC,
SyntaxKind.PARENTHESISED_TYPE_DESC
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,25 @@ public void test(String config) throws IOException, WorkspaceDocumentException {
sourcePath, actual.edits, testConfig)) {
misMatched = true;
}
actual.command = actualCommand;
if (actualCommand.get("command").getAsString().equals("ADD_DOC")) {
JsonObject actualNodeRange = getNodeRange(actualArgs);
JsonObject expNodeRange = getNodeRange(expArgs);
assert actualNodeRange != null;
if (!actualNodeRange.equals(expNodeRange)) {
misMatched = true;
JsonArray newArgs = getNodeRangeArgument(actualArgs);
if (newArgs != null) {
JsonObject command = new JsonObject();
command.add("title", actualCommand.get("title"));
command.add("command", actualCommand.get("command"));
command.add("arguments", getNodeRangeArgument(actualArgs));
actual.command = command;
}
}
}
if (actual.command == null) {
actual.command = actualCommand;
}
}
}

Expand Down Expand Up @@ -230,6 +248,31 @@ public void test(String config) throws IOException, WorkspaceDocumentException {
}
}

private JsonArray getNodeRangeArgument(JsonArray arguments) {
for (JsonElement arg : arguments) {
JsonObject argObj = arg.getAsJsonObject();
if ("node.range".equals(argObj.get("key").getAsString())) {
JsonArray array = new JsonArray(1);
array.add(argObj);
return array;
}
}
return null;
}

private JsonObject getNodeRange(JsonArray args) {
if (args == null) {
return null;
}
for (JsonElement arg : args) {
JsonObject argObj = arg.getAsJsonObject();
if ("node.range".equals(argObj.get("key").getAsString())) {
return argObj.get("value").getAsJsonObject();
}
}
return null;
}

public String getResponse(Path sourcePath, Range range, CodeActionContext codeActionContext) {
return TestUtil.getCodeActionResponse(getServiceEndpoint(), sourcePath.toString(), range, codeActionContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public Object[][] dataProvider() {
{"serviceDocumentation1.json"},
// Already documented nodes
{"documentAlreadyDocumentedConfig1.json"},
{"singleDocGeneration13.json"},
{"singleDocGeneration14.json"},
{"singleDocGeneration15.json"},
{"singleDocGeneration16.json"},
{"singleDocGeneration17.json"},
{"singleDocGeneration18.json"},
{"singleDocGeneration19.json"},
{"singleDocGeneration20.json"},
{"singleDocGeneration21.json"},
{"singleDocGeneration22.json"},
{"singleDocGeneration23.json"},
{"singleDocGeneration24.json"},
{"singleDocGeneration25.json"},
{"singleDocGeneration26.json"},
{"singleDocGeneration27.json"},
{"singleDocGeneration28.json"},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"character": 0
},
"end": {
"line": 91,
"character": 10
"line": 95,
"character": 1
}
}
}
]
}
},
"resolvable": false
},
{
"title": "Document all",
Expand All @@ -34,7 +35,8 @@
"title": "Document all",
"command": "ADD_ALL_DOC",
"arguments": []
}
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 97,
"character": 8
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 97,
"character": 0
},
"end": {
"line": 97,
"character": 22
}
}
}
]
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 99,
"character": 8
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 99,
"character": 0
},
"end": {
"line": 99,
"character": 21
}
}
}
]
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 101,
"character": 8
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 101,
"character": 0
},
"end": {
"line": 101,
"character": 33
}
}
}
]
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 103,
"character": 7
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 103,
"character": 0
},
"end": {
"line": 103,
"character": 12
}
}
}
]
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 105,
"character": 7
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 105,
"character": 0
},
"end": {
"line": 105,
"character": 20
}
}
}
]
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 107,
"character": 6
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 107,
"character": 0
},
"end": {
"line": 107,
"character": 23
}
}
}
]
},
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"position": {
"line": 109,
"character": 10
},
"source": "singleDocGeneration.bal",
"expected": [
{
"title": "Document this",
"command": {
"title": "Document this",
"command": "ADD_DOC",
"arguments": [
{
"key": "node.range",
"value": {
"start": {
"line": 109,
"character": 0
},
"end": {
"line": 109,
"character": 32
}
}
}
]
},
"resolvable": false
}
]
}
Loading

0 comments on commit 54a7ef1

Please sign in to comment.