Skip to content

Commit

Permalink
Fix filterText and sorting for method declaration completions
Browse files Browse the repository at this point in the history
Signed-off-by: Hope Hadfield <[email protected]>
  • Loading branch information
hopehadfield authored and rgrunber committed Oct 18, 2023
1 parent 8b2f626 commit a763751
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static StringBuilder createMethodProposalDescription(CompletionProposal p
case CompletionProposal.METHOD_NAME_REFERENCE:
case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
case CompletionProposal.CONSTRUCTOR_INVOCATION:
case CompletionProposal.METHOD_DECLARATION:

// method name
description.append(proposal.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public int compare(CompletionProposal p1, CompletionProposal p2) {
res = p1.getKind() - p2.getKind();
}
if (res == 0) {
char[] completion1 = getCompletion(p1);
char[] completion2 = getCompletion(p2);
char[] completion1 = p1.getKind() == CompletionProposal.METHOD_DECLARATION ? p1.getName() : getCompletion(p1);
char[] completion2 = p2.getKind() == CompletionProposal.METHOD_DECLARATION ? p2.getName() : getCompletion(p2);

int p1Length = completion1.length;
int p2Length = completion2.length;
Expand All @@ -122,7 +122,7 @@ public int compare(CompletionProposal p1, CompletionProposal p2) {
}
CompletionItemKind p1Kind = mapKind(p1);
CompletionItemKind p2Kind = mapKind(p2);
if (res == 0 && (p1Kind == CompletionItemKind.Method || p1Kind == CompletionItemKind.Constructor)
if (res == 0 && (p1Kind == CompletionItemKind.Method || p1Kind == CompletionItemKind.Constructor)
&& (p2Kind == CompletionItemKind.Method || p2Kind == CompletionItemKind.Constructor)) {
int paramCount1 = Signature.getParameterCount(p1.getSignature());
int paramCount2 = Signature.getParameterCount(p2.getSignature());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3744,15 +3744,17 @@ public void testCompletion_MatchCaseFirstLetterForMethodOverride() throws Except
//@formatter:off
"package org.sample",
"public class Test {",
" public void testMethod(){}",
" public void testMethod(int a, int b){}",
" public void testMethod(int b){}",
"}",
"class TestOverride extends Test{",
" t",
"}"));
//@formatter:on
CompletionList list = requestCompletions(unit, "t");
assertFalse(list.getItems().isEmpty());
assertTrue(list.getItems().get(1).getLabel().startsWith("testMethod"));
assertTrue(list.getItems().get(0).getLabel().startsWith("testMethod(int b"));
assertTrue(list.getItems().get(1).getLabel().startsWith("testMethod(int a"));
}

// https://github.com/eclipse/eclipse.jdt.ls/issues/2376
Expand Down

0 comments on commit a763751

Please sign in to comment.