From 0b2e95a23dfd6e9019770b1f94f3e27794caea3a Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 15 Apr 2015 18:46:58 +0300 Subject: [PATCH] IDEA-136646 IDE should be responsive during global inspections --- .../ex/GlobalInspectionContextImpl.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 8aedfc4f4cae..4e3d7b53feb8 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -325,12 +325,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp appendPairedInspectionsForUnfairTools(globalTools, globalSimpleTools, localTools); ((RefManagerImpl)getRefManager()).initializeAnnotators(); - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - runGlobalTools(scope, inspectionManager, globalTools); - } - }); + runGlobalTools(scope, inspectionManager, globalTools); if (runGlobalToolsOnly) return; @@ -497,15 +492,16 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp return PsiDocumentManager.getInstance(getProject()).getDocument(file); } - private void runGlobalTools(@NotNull AnalysisScope scope, @NotNull InspectionManager inspectionManager, @NotNull List globalTools) { + private void runGlobalTools(@NotNull final AnalysisScope scope, @NotNull final InspectionManager inspectionManager, @NotNull List globalTools) { + LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed(), "Must not run under read action, too unresponsive"); final List needRepeatSearchRequest = new ArrayList(); - final boolean surelyNoExternalUsages = scope.getScopeType() == AnalysisScope.PROJECT; + final boolean canBeExternalUsages = scope.getScopeType() != AnalysisScope.PROJECT; for (Tools tools : globalTools) { for (ScopeToolState state : tools.getTools()) { - InspectionToolWrapper toolWrapper = state.getTool(); - GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool(); - InspectionToolPresentation toolPresentation = getPresentation(toolWrapper); + final InspectionToolWrapper toolWrapper = state.getTool(); + final GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool(); + final InspectionToolPresentation toolPresentation = getPresentation(toolWrapper); try { if (tool.isGraphNeeded()) { try { @@ -516,11 +512,17 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp throw e; } } - tool.runInspection(scope, inspectionManager, this, toolPresentation); - //skip phase when we are sure that scope already contains everything - if (!surelyNoExternalUsages && tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) { - needRepeatSearchRequest.add(toolWrapper); - } + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + tool.runInspection(scope, inspectionManager, GlobalInspectionContextImpl.this, toolPresentation); + //skip phase when we are sure that scope already contains everything + if (canBeExternalUsages && + tool.queryExternalUsagesRequests(inspectionManager, GlobalInspectionContextImpl.this, toolPresentation)) { + needRepeatSearchRequest.add(toolWrapper); + } + } + }); } catch (ProcessCanceledException e) { throw e;