From bca1ab39a861de543ceb2bd3ef2e9b86392416f8 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 1 Apr 2016 14:14:21 +0200 Subject: [PATCH] don't wrap automatic QuestionAction invocation into a command with meaningless name --- .../actions/ShowIntentionActionsAction.java | 21 +++++++++++++++++++ .../impl/ShowIntentionActionsHandler.java | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/actions/ShowIntentionActionsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/actions/ShowIntentionActionsAction.java index 38e50e7fdef9..ced9efd6af9b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/actions/ShowIntentionActionsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/actions/ShowIntentionActionsAction.java @@ -20,6 +20,12 @@ import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.codeInsight.actions.BaseCodeInsightAction; import com.intellij.codeInsight.hint.HintManagerImpl; import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiUtilBase; import org.jetbrains.annotations.NotNull; /** @@ -30,6 +36,21 @@ public class ShowIntentionActionsAction extends BaseCodeInsightAction implements setEnabledInModalContext(true); } + @Override + public void actionPerformed(AnActionEvent e) { + Project project = e.getProject(); + if (project == null) return; + + Editor editor = getEditor(e.getDataContext(), project, false); + if (editor == null) return; + + final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project); + if (psiFile == null) return; + + if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return; + getHandler().invoke(project, editor, psiFile); + } + @Override protected boolean isValidForLookup() { return true; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index 94aa2c74837e..e33fec88984a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -70,7 +70,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { } final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); - codeAnalyzer.autoImportReferenceAtCursor(editor, file); //let autoimport complete + letAutoImportComplete(editor, file, codeAnalyzer); ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo(); ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1); @@ -98,6 +98,10 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { } } + private static void letAutoImportComplete(@NotNull Editor editor, @NotNull PsiFile file, DaemonCodeAnalyzerImpl codeAnalyzer) { + CommandProcessor.getInstance().runUndoTransparentAction(() -> codeAnalyzer.autoImportReferenceAtCursor(editor, file)); + } + @Override public boolean startInWriteAction() { return false;