Skip to content

Hide completions when signature help is enabled #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public List<CompletionItem> getCompletionItems() {
return completionItems;
}

private static Set<Integer> 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));
Expand All @@ -230,9 +232,14 @@ public CompletionItem toCompletionItem(CompletionProposal proposal, int index) {
this.descriptionProvider.updateDescription(proposal, $);
$.setSortText(SortTextHelper.computeSortText(proposal));
proposalProvider.updateReplacement(proposal, $, '\0');
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()));
}
// Make sure `filterText` matches `textEdit`
// See https://github.com/eclipse/eclipse.jdt.ls/issues/1348
if ($.getTextEdit() != null) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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});");
Expand Down Expand Up @@ -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);
}
}