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 d7be6703bef7..58cd8588d320 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 @@ -14,6 +14,7 @@ import com.intellij.codeInsight.hint.HintManagerImpl; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.IntentionActionDelegate; import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; +import com.intellij.codeInsight.intention.impl.preview.IntentionPreviewEditor; import com.intellij.codeInsight.intention.impl.preview.IntentionPreviewUnsupportedOperationException; import com.intellij.codeInsight.lookup.LookupEx; import com.intellij.codeInsight.lookup.LookupManager; @@ -172,24 +173,33 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { @NotNull Editor hostEditor, @Nullable PsiFile injectedFile, @NotNull PairProcessor predicate) { - if (injectedFile == null) { - return Pair.create(hostFile, hostEditor); - } - Editor editorToApply = null; - PsiFile fileToApply = null; + try { + Editor editorToApply = null; + PsiFile fileToApply = null; - Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile); - if (predicate.process(injectedFile, injectedEditor)) { - editorToApply = injectedEditor; - fileToApply = injectedFile; - } + Editor injectedEditor = null; + // TODO: support intention preview in injections + if (injectedFile != null && !(hostEditor instanceof IntentionPreviewEditor)) { + injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile); + if (predicate.process(injectedFile, injectedEditor)) { + editorToApply = injectedEditor; + fileToApply = injectedFile; + } + } - if (editorToApply == null && hostEditor != injectedEditor && predicate.process(hostFile, hostEditor)) { - editorToApply = hostEditor; - fileToApply = hostFile; + if (editorToApply == null && hostEditor != injectedEditor && predicate.process(hostFile, hostEditor)) { + editorToApply = hostEditor; + fileToApply = hostFile; + } + if (editorToApply == null) return null; + return Pair.create(fileToApply, editorToApply); + } + catch (IntentionPreviewUnsupportedOperationException e) { + if (ApplicationManager.getApplication().isUnitTestMode()) { + throw e; + } + return null; } - if (editorToApply == null) return null; - return Pair.create(fileToApply, editorToApply); } public static boolean chooseActionAndInvoke(@NotNull PsiFile hostFile,