Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Master] Improve the order of completions for client resource access action statements #42551

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we considering alphabetic order or any other order when re-ordering resource-function paths?

Copy link
Contributor Author

@nipunayf nipunayf May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM there are no such explicit sorts, and we are preserving the order in which the user has defined the resource methods in the class.

Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,38 @@ public void sort(BallerinaCompletionContext context, ClientResourceAccessActionN
Optional<TypeSymbol> parameterSymbol = getParameterTypeSymbol(context);
for (int i = 0; i < completionItems.size(); i++) {
LSCompletionItem completionItem = completionItems.get(i);
if (completionItem.getType() == LSCompletionItem.CompletionItemType.NAMED_ARG) {
LSCompletionItem.CompletionItemType type = completionItem.getType();
if (type == LSCompletionItem.CompletionItemType.NAMED_ARG) {
sortNamedArgCompletionItem(context, completionItem);
} else if (parameterSymbol.isEmpty()) {
sortParameterlessCompletionItem(context, completionItem);
} else if (completionItem.getType() == LSCompletionItem.CompletionItemType.SYMBOL) {
SymbolCompletionItem symbolCompletionItem = (SymbolCompletionItem) completionItem;
if (symbolCompletionItem.getSymbol().isPresent() &&
symbolCompletionItem.getSymbol().get().kind() == SymbolKind.RESOURCE_METHOD) {
completionItem.getCompletionItem().setSortText(
SortingUtil.genSortTextByAssignability(context, completionItem, parameterSymbol.get()) +
SortingUtil.genSortText(i + 1));
}
sortDefaultCompletionItem(context, parameterSymbol.get(), completionItem);
sortParameterlessCompletionItem(context, i, completionItem);
} else if (type == LSCompletionItem.CompletionItemType.SYMBOL) {
sortSymbolCompletionItem(context, parameterSymbol.get(), i, completionItem);
} else {
sortDefaultCompletionItem(context, parameterSymbol.get(), completionItem);
}
}
}

private static void sortParameterlessCompletionItem(BallerinaCompletionContext context, int rank,
LSCompletionItem completionItem) {
completionItem.getCompletionItem().setSortText(SortingUtil.genSortText(
SortingUtil.toRank(context, completionItem)) + SortingUtil.genSortText(rank + 1));
}

private static void sortSymbolCompletionItem(BallerinaCompletionContext context, TypeSymbol parameterSymbol,
int rank, LSCompletionItem completionItem) {
SymbolCompletionItem symbolCompletionItem = (SymbolCompletionItem) completionItem;
Optional<Symbol> symbol = symbolCompletionItem.getSymbol();
if (symbol.isPresent() && symbol.get().kind() == SymbolKind.RESOURCE_METHOD) {
completionItem.getCompletionItem().setSortText(
SortingUtil.genSortTextByAssignability(context, completionItem, parameterSymbol) +
SortingUtil.genSortText(rank + 1));
return;
}
sortDefaultCompletionItem(context, parameterSymbol, completionItem);
}

private List<LSCompletionItem> getPathSegmentCompletionItems(ClientResourceAccessActionNode node,
BallerinaCompletionContext context,
List<ResourceMethodSymbol> resourceMethods,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected static void sortNamedArgCompletionItem(BallerinaCompletionContext cont
completionItem.getCompletionItem().setSortText(sortText);
}

protected static void sortParameterlessCompletionItem(BallerinaCompletionContext context,
private static void sortParameterlessCompletionItem(BallerinaCompletionContext context,
LSCompletionItem completionItem) {
completionItem.getCompletionItem().setSortText(SortingUtil.genSortText(
SortingUtil.toRank(context, completionItem)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CB",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -76,7 +76,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n \n**Return** `int` \n \n"
}
},
"sortText": "C",
"sortText": "CC",
"filterText": "path2|get",
"insertText": "/path2;",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -106,7 +106,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CD",
"filterText": "path2|post",
"insertText": "/path2/[${1:\"path\"}].post(${2});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -140,7 +140,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CE",
"filterText": "path2|post",
"insertText": "/path2/${1:path}.post(${2});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -174,7 +174,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CF",
"filterText": "path3|post",
"insertText": "/path3.post(${1});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CB",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -76,7 +76,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n \n**Return** `int` \n \n"
}
},
"sortText": "C",
"sortText": "CC",
"filterText": "path2|get",
"insertText": "/path2;",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -106,7 +106,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CD",
"filterText": "path2|post",
"insertText": "/path2/[${1:\"path\"}].post(${2});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -140,7 +140,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CE",
"filterText": "path2|post",
"insertText": "/path2/${1:path}.post(${2});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CB",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -76,7 +76,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CC",
"filterText": "path3|post",
"insertText": "/path3.post(${1});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n \n \n**Return** `string` \n \n"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "path1|get",
"insertText": "/path1;",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` a \n- `int` b"
}
},
"sortText": "C",
"sortText": "CB",
"filterText": "post",
"insertText": "/.post(${1});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -80,7 +80,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CC",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -110,7 +110,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CD",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -140,7 +140,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1"
}
},
"sortText": "C",
"sortText": "CE",
"filterText": "path1|get",
"insertText": "/path1/[${1:\"path\"}];",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -170,7 +170,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1"
}
},
"sortText": "C",
"sortText": "CF",
"filterText": "path1|get",
"insertText": "/path1/${1:path};",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -200,7 +200,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n \n**Return** `int` \n \n"
}
},
"sortText": "C",
"sortText": "CG",
"filterText": "path1|path2|get",
"insertText": "/path1/[${1:\"path\"}]/path2;",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -230,7 +230,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n \n**Return** `int` \n \n"
}
},
"sortText": "C",
"sortText": "CH",
"filterText": "path1|path2|get",
"insertText": "/path1/${1:path}/path2;",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -260,7 +260,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CI",
"filterText": "path1|path2|post",
"insertText": "/path1/[${1:\"path\"}]/path2/[${2:\"path\"}].post(${3});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -294,7 +294,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CJ",
"filterText": "path1|path2|post",
"insertText": "/path1/${1:path}/path2/${2:path}.post(${3});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -328,7 +328,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CK",
"filterText": "path1|path3|post",
"insertText": "/path1/[${1:\"path\"}]/path3.post(${2});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -362,7 +362,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CL",
"filterText": "path1|path3|post",
"insertText": "/path1/${1:path}/path3.post(${2});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` a \n- `int` b"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "post",
"insertText": "/.post(${1})",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet"
Expand All @@ -31,7 +31,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CB",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet"
Expand All @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CC",
"filterText": "|post",
"insertText": "/[${1:\"path\"}].post(${2});",
"insertTextFormat": "Snippet",
Expand All @@ -65,7 +65,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CD",
"filterText": "|post",
"insertText": "/${1:path}.post(${2});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "C",
"sortText": "CB",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -76,7 +76,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CC",
"filterText": "|post",
"insertText": "/[${1:\"path\"}].post(${2});",
"insertTextFormat": "Snippet",
Expand Down Expand Up @@ -110,7 +110,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CD",
"filterText": "|post",
"insertText": "/${1:path}.post(${2});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "C",
"sortText": "CA",
"filterText": "post",
"insertText": ".post(${1})",
"insertTextFormat": "Snippet",
Expand Down
Loading
Loading