Search in sources :

Example 1 with IntentionHintComponent

use of com.intellij.codeInsight.intention.impl.IntentionHintComponent in project intellij-community by JetBrains.

the class DaemonCodeAnalyzerImpl method setLastIntentionHint.

void setLastIntentionHint(@NotNull Project project, @NotNull PsiFile file, @NotNull Editor editor, @NotNull ShowIntentionsPass.IntentionsInfo intentions, boolean hasToRecreate) {
    if (!editor.getSettings().isShowIntentionBulb()) {
        return;
    }
    ApplicationManager.getApplication().assertIsDispatchThread();
    hideLastIntentionHint();
    if (editor.getCaretModel().getCaretCount() > 1)
        return;
    IntentionHintComponent hintComponent = IntentionHintComponent.showIntentionHint(project, file, editor, intentions, false);
    if (hasToRecreate) {
        hintComponent.recreate();
    }
    myLastIntentionHint = hintComponent;
}
Also used : IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent)

Example 2 with IntentionHintComponent

use of com.intellij.codeInsight.intention.impl.IntentionHintComponent in project intellij-community by JetBrains.

the class DaemonCodeAnalyzerImpl method hideLastIntentionHint.

void hideLastIntentionHint() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    IntentionHintComponent hint = myLastIntentionHint;
    if (hint != null && hint.isVisible()) {
        hint.hide();
        myLastIntentionHint = null;
    }
}
Also used : IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent)

Example 3 with IntentionHintComponent

use of com.intellij.codeInsight.intention.impl.IntentionHintComponent in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testLightBulbIsHiddenWhenFixRangeIsCollapsed.

public void testLightBulbIsHiddenWhenFixRangeIsCollapsed() {
    configureByText(StdFileTypes.JAVA, "class S { void foo() { boolean var; if (<selection>va<caret>r</selection>) {}} }");
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(1000, 1000);
    final Set<LightweightHint> visibleHints = ContainerUtil.newIdentityTroveSet();
    getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(EditorHintListener.TOPIC, new EditorHintListener() {

        @Override
        public void hintShown(final Project project, final LightweightHint hint, final int flags) {
            visibleHints.add(hint);
            hint.addHintListener(new HintListener() {

                @Override
                public void hintHidden(EventObject event) {
                    visibleHints.remove(hint);
                    hint.removeHintListener(this);
                }
            });
        }
    });
    highlightErrors();
    IntentionHintComponent lastHintBeforeDeletion = myDaemonCodeAnalyzer.getLastIntentionHint();
    assertNotNull(lastHintBeforeDeletion);
    delete(myEditor);
    highlightErrors();
    IntentionHintComponent lastHintAfterDeletion = myDaemonCodeAnalyzer.getLastIntentionHint();
    assertSame(lastHintBeforeDeletion, lastHintAfterDeletion);
    assertEmpty(visibleHints);
}
Also used : EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) HintListener(com.intellij.ui.HintListener) Project(com.intellij.openapi.project.Project) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint) LightweightHint(com.intellij.ui.LightweightHint)

Example 4 with IntentionHintComponent

use of com.intellij.codeInsight.intention.impl.IntentionHintComponent in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testBulbAppearsAfterType.

public void testBulbAppearsAfterType() throws Throwable {
    String text = "class S { ArrayList<caret>XXX x;}";
    configureByText(StdFileTypes.JAVA, text);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(1000, 1000);
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
    final Set<LightweightHint> shown = ContainerUtil.newIdentityTroveSet();
    getProject().getMessageBus().connect().subscribe(EditorHintListener.TOPIC, (project, hint, flags) -> {
        shown.add(hint);
        hint.addHintListener(event -> shown.remove(hint));
    });
    DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
    highlightErrors();
    IntentionHintComponent hintComponent = codeAnalyzer.getLastIntentionHint();
    assertNotNull(hintComponent);
    assertFalse(hintComponent.isDisposed());
    assertNotNull(hintComponent.getComponentHint());
    assertTrue(shown.contains(hintComponent.getComponentHint()));
    type("x");
    highlightErrors();
    hintComponent = codeAnalyzer.getLastIntentionHint();
    assertNotNull(hintComponent);
    assertFalse(hintComponent.isDisposed());
    assertNotNull(hintComponent.getComponentHint());
    assertTrue(shown.contains(hintComponent.getComponentHint()));
}
Also used : IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint)

Example 5 with IntentionHintComponent

use of com.intellij.codeInsight.intention.impl.IntentionHintComponent in project intellij-community by JetBrains.

the class ShowIntentionsPass method updateActions.

private void updateActions(@NotNull DaemonCodeAnalyzerImpl codeAnalyzer) {
    IntentionHintComponent hintComponent = codeAnalyzer.getLastIntentionHint();
    if (!myShowBulb || hintComponent == null || !hintComponent.isForEditor(myEditor)) {
        return;
    }
    IntentionHintComponent.PopupUpdateResult result = hintComponent.updateActions(myIntentionsInfo);
    if (result == IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE) {
    // reshow all
    } else if (result == IntentionHintComponent.PopupUpdateResult.CHANGED_INVISIBLE) {
        myHasToRecreate = true;
    }
}
Also used : IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent)

Aggregations

IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)5 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)2 LightweightHint (com.intellij.ui.LightweightHint)2 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1 Project (com.intellij.openapi.project.Project)1 HintListener (com.intellij.ui.HintListener)1