Skip to content

Commit

Permalink
Merge pull request #42727 from nipunayf/fix-42549-9.x
Browse files Browse the repository at this point in the history
[2201.9.x] Improve the order of completions for client resource access action statements
  • Loading branch information
nipunayf committed May 14, 2024
2 parents e3ee02d + 1f7f7e6 commit bc31254
Show file tree
Hide file tree
Showing 34 changed files with 845 additions and 186 deletions.
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

0 comments on commit bc31254

Please sign in to comment.