From 3ac75bda371679d6e22ea809214907d549bdc185 Mon Sep 17 00:00:00 2001 From: shaiahr Date: Mon, 26 Apr 2021 17:49:22 +0300 Subject: [PATCH] Insert the selected completion even when completions are blocked. (#136) * Insert the selected completion even when completions are blocked. * Fix failing test. --- .../intellij/completions/LimitExceededLookupElement.java | 9 ++++++--- .../completions/TabNineCompletionContributor.java | 4 ++-- .../integration/BinaryBadResultsIntegrationTests.java | 8 ++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tabnine/intellij/completions/LimitExceededLookupElement.java b/src/main/java/com/tabnine/intellij/completions/LimitExceededLookupElement.java index 14c948f7d..6aeb5dbc7 100644 --- a/src/main/java/com/tabnine/intellij/completions/LimitExceededLookupElement.java +++ b/src/main/java/com/tabnine/intellij/completions/LimitExceededLookupElement.java @@ -2,7 +2,9 @@ import com.intellij.codeInsight.daemon.impl.HintRenderer; import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupElementDecorator; import com.intellij.codeInsight.lookup.LookupEvent; +import com.intellij.codeInsight.lookup.LookupListener; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.ControlFlowException; import com.intellij.openapi.diagnostic.Logger; @@ -29,11 +31,12 @@ * indicating the quota was exceeded. Hovering the mouse over this inlay open a balloon with more details and possibly * CTA links. */ -public class LimitExceededLookupElement extends InsertNothingLookupElement { +public class LimitExceededLookupElement extends LookupElementDecorator + implements LookupListener { private final BinaryRequestFacade binaryRequestFacade = DependencyContainer.instanceOfBinaryRequestFacade(); - protected LimitExceededLookupElement(LookupElement delegate, String prefix) { - super(delegate, prefix); + protected LimitExceededLookupElement(LookupElement delegate) { + super(delegate); } @Override diff --git a/src/main/java/com/tabnine/intellij/completions/TabNineCompletionContributor.java b/src/main/java/com/tabnine/intellij/completions/TabNineCompletionContributor.java index af45fc7d0..865ae171d 100644 --- a/src/main/java/com/tabnine/intellij/completions/TabNineCompletionContributor.java +++ b/src/main/java/com/tabnine/intellij/completions/TabNineCompletionContributor.java @@ -134,8 +134,8 @@ public void renderElement( } }); if (locked) { - final InsertNothingLookupElement lookupElement = new LimitExceededLookupElement( - lookupElementBuilder, oldPrefix); + final LimitExceededLookupElement lookupElement = new LimitExceededLookupElement( + lookupElementBuilder); if (activeLookup != null) { activeLookup.addLookupListener(lookupElement); } diff --git a/src/test/java/com/tabnine/integration/BinaryBadResultsIntegrationTests.java b/src/test/java/com/tabnine/integration/BinaryBadResultsIntegrationTests.java index 1cdd9e3cb..dd8f4a748 100644 --- a/src/test/java/com/tabnine/integration/BinaryBadResultsIntegrationTests.java +++ b/src/test/java/com/tabnine/integration/BinaryBadResultsIntegrationTests.java @@ -2,6 +2,7 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.tabnine.binary.exceptions.TabNineDeadException; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.stubbing.Answer; @@ -20,6 +21,13 @@ import static org.mockito.Mockito.*; public class BinaryBadResultsIntegrationTests extends MockedBinaryCompletionTestCase { + + @Before + public void beforeEach() { + myFixture.completeBasic(); //make sure all singletons are inited + clearInvocations(binaryProcessGatewayProviderMock); + } + @Test public void givenACompletionWhenIOExceptionWasThrownThenBinaryIsRestarted() throws Exception { when(binaryProcessGatewayMock.readRawResponse()).thenThrow(new IOException());