diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java index 01448d57a9..f42e0d9be9 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java @@ -210,6 +210,8 @@ public List getCompletionItems() { return completionItems; } + private static Set PREFER_SIGNATURE_HELP_COMPLETION_ITEMS = Set.of(CompletionProposal.METHOD_REF, CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION); + public CompletionItem toCompletionItem(CompletionProposal proposal, int index) { final CompletionItem $ = new CompletionItem(); $.setKind(mapKind(proposal)); @@ -232,7 +234,12 @@ public CompletionItem toCompletionItem(CompletionProposal proposal, int index) { proposalProvider.updateReplacement(proposal, $, '\0'); // Make sure `filterText` matches `textEdit` // See https://github.com/eclipse/eclipse.jdt.ls/issues/1348 - if ($.getTextEdit() != null) { + boolean isSignatureHelpEnabled = preferenceManager.getPreferences().isSignatureHelpEnabled(); + // Hide completions when signature help is visible. + if (isSignatureHelpEnabled && PREFER_SIGNATURE_HELP_COMPLETION_ITEMS.contains(proposal.getKind())) { + $.setFilterText(new String(proposal.getName())); + } + if ($.getFilterText() == null && $.getTextEdit() != null) { String newText = $.getTextEdit().isLeft() ? $.getTextEdit().getLeft().getNewText() : $.getTextEdit().getRight().getNewText(); Range range = $.getTextEdit().isLeft() ? $.getTextEdit().getLeft().getRange() : ($.getTextEdit().getRight().getInsert() != null ? $.getTextEdit().getRight().getInsert() : $.getTextEdit().getRight().getReplace()); if (proposal.getKind() == CompletionProposal.TYPE_REF && range != null && newText != null) { diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionHandlerTest.java index f0eb2afbf2..042bbb4137 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionHandlerTest.java @@ -315,6 +315,23 @@ public void testCompletion_constructor() throws Exception{ assertEquals(18, range.getEnd().getCharacter()); } + @Test + public void testCompletion_constructor_withParameterHelpEnabled() throws JavaModelException { + enableSignatureHelp(); + + ICompilationUnit unit = getWorkingCopy( + "src/java/Foo.java", + "public class MyUniqueClassName {\n"+ + " void foo() {\n"+ + " new MyUniqueClass\n"+ + " }\n"+ + "}\n"); + + + CompletionList list = requestCompletions(unit, "new MyUniqueClass"); + assertEquals("MyUniqueClassName", list.getItems().get(0).getFilterText()); + } + @Test public void testCompletion_import_package() throws JavaModelException{ @@ -670,6 +687,21 @@ public void testCompletion_method_withLSPV3() throws JavaModelException{ assertEquals(2, edits.size()); } + @Test + public void testCompletion_method_withSignatureHelpEnabled() throws JavaModelException { + enableSignatureHelp(); + ICompilationUnit unit = getWorkingCopy( + "src/java/Foo.java", + "public class Foo {\n"+ + " void foo(String parameter) {\n"+ + "parameter.lengt\n" + + " }\n"+ + "}\n"); + + CompletionList list = requestCompletions(unit, "parameter.lengt"); + assertEquals("put", list.getItems().get(0).getFilterText()); + } + @Test public void testCompletion_method_guessMethodArgumentsFalse() throws JavaModelException { testCompletion_method_guessMethodArguments(false, "test(${1:name}, ${2:i});"); @@ -3124,4 +3156,10 @@ private void mockLSPClient(boolean isSnippetSupported, boolean isSignatureHelpSu when(mockCapabilies.isSignatureHelpSupported()).thenReturn(isSignatureHelpSuported); when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); } + + private void enableSignatureHelp() { + Preferences preferencesSpy = Mockito.spy(preferences); + when(preferencesSpy.isSignatureHelpEnabled()).thenReturn(true); + when(preferenceManager.getPreferences()).thenReturn(preferencesSpy); + } }