Skip to content

Commit

Permalink
Preserve the given order of resource paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Nov 8, 2023
1 parent a286dbb commit 381bef4
Show file tree
Hide file tree
Showing 26 changed files with 135 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ private static ResourceAccessPathPart getResourceAccessPartForSegment(PathSegmen
new ResourceAccessPathPart(computedInsertText, computedSignature);
if (context.currentSemanticModel().isPresent() &&
context.currentSemanticModel().get().types().STRING.subtypeOf(typeSymbol)) {
resourceAccessPathPart.namedPathSignature = pathParameterSymbol.getName().isPresent() ?
"<" + pathParameterSymbol.getName().get() + ">" : "<path>";;
resourceAccessPathPart.namedPathSignature = "<" +
(pathParameterSymbol.getName().isPresent() ? pathParameterSymbol.getName().get() : "path") + ">";
resourceAccessPathPart.namedPathInsertText = "${" + placeHolderIndex + ":" + "path" + "}";
resourceAccessPathPart.computedPathInsertText = "[${" + placeHolderIndex + ":" + "\"path\"" + "}]";
resourceAccessPathPart.isStringPathPram = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -543,6 +544,7 @@ protected List<LSCompletionItem> expressionCompletions(BallerinaCompletionContex
Predicate<Symbol> symbolFilter = getExpressionContextSymbolFilter();
List<Symbol> filteredList = visibleSymbols.stream()
.filter(symbolFilter)
.sorted(Comparator.comparing(symbol -> symbol.getName().get()))
.collect(Collectors.toList());
completionItems.addAll(this.getCompletionItemList(filteredList, context));
completionItems.addAll(this.getBasicAndOtherTypeCompletions(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public List<LSCompletionItem> getCompletions(BallerinaCompletionContext context,
@Override
public void sort(BallerinaCompletionContext context, AsyncSendActionNode node,
List<LSCompletionItem> completionItems) {
int rankOffset = 1;
for (LSCompletionItem completionItem : completionItems) {
sortByAssignability(context, completionItem, SortingUtil.toRank(context, completionItem));
sortByAssignability(context, completionItem, SortingUtil.toRank(context, completionItem, rankOffset));
rankOffset++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.ballerina.compiler.api.symbols.ParameterSymbol;
import io.ballerina.compiler.api.symbols.RecordFieldSymbol;
import io.ballerina.compiler.api.symbols.RecordTypeSymbol;
import io.ballerina.compiler.api.symbols.SymbolKind;
import io.ballerina.compiler.api.symbols.TypeDescKind;
import io.ballerina.compiler.api.symbols.TypeSymbol;
import io.ballerina.compiler.syntax.tree.ExplicitNewExpressionNode;
Expand All @@ -40,6 +41,7 @@
import org.ballerinalang.langserver.commons.completion.LSCompletionException;
import org.ballerinalang.langserver.commons.completion.LSCompletionItem;
import org.ballerinalang.langserver.completions.NamedArgCompletionItem;
import org.ballerinalang.langserver.completions.SymbolCompletionItem;
import org.ballerinalang.langserver.completions.builder.NamedArgCompletionItemBuilder;
import org.ballerinalang.langserver.completions.providers.AbstractCompletionProvider;
import org.ballerinalang.langserver.completions.util.SortingUtil;
Expand Down Expand Up @@ -89,6 +91,7 @@ public void sort(BallerinaCompletionContext context, T node, List<LSCompletionIt
context.getCursorPosition().getCharacter()));
}

int rankOffset = 1;
for (LSCompletionItem completionItem : completionItems) {
if (completionItem.getType() == LSCompletionItem.CompletionItemType.NAMED_ARG) {
NamedArgCompletionItem argCompletionItem = (NamedArgCompletionItem) completionItem;
Expand All @@ -111,10 +114,21 @@ public void sort(BallerinaCompletionContext context, T node, List<LSCompletionIt
} else if (parameterSymbol.isEmpty()) {
completionItem.getCompletionItem().setSortText(SortingUtil.genSortText(
SortingUtil.toRank(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(rankOffset));
}
completionItem.getCompletionItem().setSortText(
SortingUtil.genSortTextByAssignability(context, completionItem, parameterSymbol.get()));
} else {
completionItem.getCompletionItem().setSortText(
SortingUtil.genSortTextByAssignability(context, completionItem, parameterSymbol.get()));
}
rankOffset++;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"value": "**Package:** _._ \n \n \n"
}
},
"sortText": "CC",
"sortText": "CD",
"filterText": "remote1",
"insertText": "remote1()",
"insertTextFormat": "Snippet"
Expand All @@ -31,7 +31,7 @@
"value": "**Package:** _._ \n \n \n \n \n**Return** `string` \n \n"
}
},
"sortText": "CC",
"sortText": "CE",
"filterText": "path1|get",
"insertText": "/path1;",
"insertTextFormat": "Snippet"
Expand All @@ -46,7 +46,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` a \n- `int` b"
}
},
"sortText": "CC",
"sortText": "CF",
"filterText": "post",
"insertText": "/.post(${1});",
"insertTextFormat": "Snippet",
Expand All @@ -65,13 +65,13 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "CC",
"sortText": "CG",
"filterText": "get",
"insertText": "/[${1:\"path\"}];",
"insertTextFormat": "Snippet"
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand All @@ -80,7 +80,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string[]` ids"
}
},
"sortText": "CC",
"sortText": "CH",
"filterText": "get",
"insertText": "/${1:path};",
"insertTextFormat": "Snippet"
Expand All @@ -95,13 +95,13 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1"
}
},
"sortText": "CC",
"sortText": "CI",
"filterText": "path1|get",
"insertText": "/path1/[${1:\"path\"}];",
"insertTextFormat": "Snippet"
},
{
"label": "/path1/<path>",
"label": "/path1/<id1>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand All @@ -110,7 +110,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1"
}
},
"sortText": "CC",
"sortText": "CJ",
"filterText": "path1|get",
"insertText": "/path1/${1:path};",
"insertTextFormat": "Snippet"
Expand All @@ -125,13 +125,13 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n \n**Return** `int` \n \n"
}
},
"sortText": "CC",
"sortText": "CK",
"filterText": "path1|path2|get",
"insertText": "/path1/[${1:\"path\"}]/path2;",
"insertTextFormat": "Snippet"
},
{
"label": "/path1/<path>/path2",
"label": "/path1/<id1>/path2",
"kind": "Function",
"detail": "int",
"documentation": {
Expand All @@ -140,7 +140,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n \n**Return** `int` \n \n"
}
},
"sortText": "CC",
"sortText": "CL",
"filterText": "path1|path2|get",
"insertText": "/path1/${1:path}/path2;",
"insertTextFormat": "Snippet"
Expand All @@ -155,7 +155,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "CC",
"sortText": "CM",
"filterText": "path1|path2|post",
"insertText": "/path1/[${1:\"path\"}]/path2/[${2:\"path\"}].post(${3});",
"insertTextFormat": "Snippet",
Expand All @@ -165,7 +165,7 @@
}
},
{
"label": "/path1/<path>/path2/<path>.post(string b, string... ids2)",
"label": "/path1/<id1>/path2/<ids>.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand All @@ -174,7 +174,7 @@
"value": "**Package:** _._ \n \n \n**Params** \n- `string` id1 \n- `string[]` ids \n- `string` b \n- `string[]` ids2"
}
},
"sortText": "CC",
"sortText": "CN",
"filterText": "path1|path2|post",
"insertText": "/path1/${1:path}/path2/${2:path}.post(${3});",
"insertTextFormat": "Snippet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -131,7 +131,7 @@
}
},
{
"label": "/path2/<path>.post(string b, string... ids2)",
"label": "/path2/<ids>.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -131,7 +131,7 @@
}
},
{
"label": "/path2/<path>.post(string b, string... ids2)",
"label": "/path2/<ids>.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
]
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -161,7 +161,7 @@
]
},
{
"label": "/path1/<path>",
"label": "/path1/<id1>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -221,7 +221,7 @@
]
},
{
"label": "/path1/<path>/path2",
"label": "/path1/<id1>/path2",
"kind": "Function",
"detail": "int",
"documentation": {
Expand Down Expand Up @@ -285,7 +285,7 @@
}
},
{
"label": "/path1/<path>/path2/<path>.post(string b, string... ids2)",
"label": "/path1/<id1>/path2/<ids>.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -353,7 +353,7 @@
}
},
{
"label": "/path1/<path>/path3.post(string b, string... ids2)",
"label": "/path1/<id1>/path3.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"insertTextFormat": "Snippet"
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -56,7 +56,7 @@
}
},
{
"label": "/<path>.post(string b, string... ids2)",
"label": "/<ids>.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down Expand Up @@ -101,7 +101,7 @@
}
},
{
"label": "/<path>.post(string b, string... ids2)",
"label": "/<ids>.post(string b, string... ids2)",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
},
{
"label": "/path1/<path>/path2/<path>.post(string str, string... ids2)",
"label": "/path1/<id1>/path2/<ids>.post(string str, string... ids2)",
"kind": "Function",
"detail": "module1:Response",
"documentation": {
Expand Down Expand Up @@ -143,7 +143,7 @@
}
},
{
"label": "/path4/<path>(module1:TargetType targetType)",
"label": "/path4/<pathParam>(module1:TargetType targetType)",
"kind": "Function",
"detail": "targetType|module1:ClientError|error",
"documentation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
},
{
"label": "/<path>",
"label": "/<ids>",
"kind": "Function",
"detail": "()",
"documentation": {
Expand Down
Loading

0 comments on commit 381bef4

Please sign in to comment.