From bd5d83972cde985144b6b111794175d4a9c7c49a Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 16 Apr 2024 00:34:32 +0530 Subject: [PATCH] Refactor sorting of completion items --- ...ClientResourceAccessActionNodeContext.java | 19 +++++++++++++++ .../InvocationNodeContextProvider.java | 23 +------------------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ClientResourceAccessActionNodeContext.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ClientResourceAccessActionNodeContext.java index 68dc061f7feb..14e43ea5026f 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ClientResourceAccessActionNodeContext.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ClientResourceAccessActionNodeContext.java @@ -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 getPathSegmentCompletionItems(ClientResourceAccessActionNode node, BallerinaCompletionContext context, List resourceMethods, diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/InvocationNodeContextProvider.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/InvocationNodeContextProvider.java index 73c5c611790b..1931ec9dd7d2 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/InvocationNodeContextProvider.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/InvocationNodeContextProvider.java @@ -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; @@ -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; @@ -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(