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;
}
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;
}
}
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);
}
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()));
}
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;
}
}
Aggregations