Skip to content

Commit

Permalink
Refactor sorting of completion items
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Apr 15, 2024
1 parent 6262569 commit bd5d839
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ public void sort(BallerinaCompletionContext context, ClientResourceAccessActionN
}
}

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;
if (symbolCompletionItem.getSymbol().isPresent() &&
symbolCompletionItem.getSymbol().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 @@ -23,7 +23,6 @@
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 @@ -41,7 +40,6 @@
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 @@ -127,31 +125,12 @@ 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)));
}

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

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

protected static void sortDefaultCompletionItem(BallerinaCompletionContext context, TypeSymbol parameterSymbol,
LSCompletionItem completionItem) {
completionItem.getCompletionItem().setSortText(
Expand Down

0 comments on commit bd5d839

Please sign in to comment.