diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/completion/IncompleteCompletionTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/completion/IncompleteCompletionTest.java index 2e1804bf6..34afb5d3f 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/completion/IncompleteCompletionTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/completion/IncompleteCompletionTest.java @@ -675,4 +675,21 @@ public void testIncompleteIndication() throws CoreException { assertEquals("FirstClass", proposalsWithIncompleteProposal[0].getDisplayString()); assertEquals("➕ Continue typing for more proposals...", proposalsWithIncompleteProposal[1].getDisplayString()); } + + @Test + public void testIncompleteIndicationWithEmptyList() throws CoreException { + MockLanguageServer.INSTANCE.setCompletionList(new CompletionList(true, List.of())); + + IFile testFile = TestUtils.createUniqueTestFile(project, ""); + ITextViewer viewer = TestUtils.openTextViewer(testFile); + + // without incomplete indication + ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(viewer, 0); + assertEquals(0, proposals.length); + + // with incomplete indication + final var incompleIndicatingProcessor = new LSContentAssistProcessor(true, true); + ICompletionProposal[] proposalsWithIncompleteProposal = incompleIndicatingProcessor.computeCompletionProposals(viewer, 0); + assertEquals(0, proposalsWithIncompleteProposal.length); + } } diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java index 7de43c7d7..4b5a75cca 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java @@ -189,7 +189,10 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int } completeProposals.sort(proposalComparator); final ICompletionProposal incompleteProposal = createIncompleteProposal(offset, anyIncomplete.get()); - if (incompleteProposal != null) { + if (incompleteProposal != null && !completeProposals.isEmpty()) { + // Only add the incompleteProposal if the list is not empty. + // Otherwise we might get a completion popup which contains only the incompleteProposal. + @SuppressWarnings("unchecked") final var incompleteProposals = (List) (List) completeProposals; incompleteProposals.add(incompleteProposal);